2-2) Checking Input and Changing Direction of The Cat

시그니천·2024년 6월 4일

[ G01 ] ZigZagRacer

목록 보기
7/26

목표 : 터치에 따라 플레이어 방향 회전하기

  • ChangeDirection()
  • CheckInput()
public class CharacterController : MonoBehaviour
{
    [SerializeField] private float moveSpeed;

    private bool movingLeft = true;

    private void Update()
    {
        Move();
        CheckInput();
    }

    private void Move()
    {
        transform.position += transform.forward * moveSpeed * Time.deltaTime;
    }

    private void CheckInput()
    {
        if(Input.GetMouseButtonDown(0))
        {
            ChangeDirection();
        }
    }

    private void ChangeDirection()
    {
        if(movingLeft) 
        {
            movingLeft = false;
            transform.rotation = Quaternion.Euler(0, 90, 0);
        }
        else 
        {
            movingLeft = true;
            transform.rotation = Quaternion.Euler(0, 0, 0);
        }
    }
}
profile
우주최강개발자

0개의 댓글