character sprite site:opengameart.org
라고 구글에 검색하면 무료오픈소스로 이동캐릭터 사진 사용할수있음
Project Settings -> Enter Play Mode Settings에서 옵션 체크박스 해주면 플레이모드할때 로딩안걸리고 바로됨.
캐릭터 그리드로 잘라주기(Grid By Cell Size)
//Background.cs 파일
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Background : MonoBehaviour
{
private float moveSpeed = 3f;
// Update is called once per frame
void Update()
{
transform.position += Vector3.down * moveSpeed *Time.deltaTime;
//Time.deltaTime는 컴퓨터 성능에 상관없이 똑같은 이동위치만큼 바뀔수 있게 설정해주는거임
if(transform.position.y < -10)
{
transform.position += new Vector3(0, 20f,0);
}
}
}
속도가 3씩밑으로 내려가면서, y축으로 -10밑으로 더 가면 위로 20 올려주고, 다시 3씩 밑으로 내려간다.
플레이어 움직이기 동작하기(키보드)
//Player.cs 파일
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
[SerializeField]
private float moveSpeed;
// Update is called once per frame
void Update()
{
//키보드 상하좌우를 누르면 값이 저 변수로 담아짐.
float horizontalInput = Input.GetAxisRaw("Horizontal");
float verticalInput = Input.GetAxisRaw("Vertical");
Vector3 moveTo = new Vector3(horizontalInput, verticalInput, 0);
transform.position += moveTo * moveSpeed * Time.deltaTime;
}
}
moveSpeed에서 속도 조절 가능
'유니티(unity)' 카테고리의 다른 글
유니티 예쁘게 정렬하는법: Add말고 AddRange() (0) | 2023.12.01 |
---|