2-4) Ignoring The First Step

시그니천·2024년 6월 4일

[ G01 ] ZigZagRacer

목록 보기
8/26

처음 눌렀을때 방향 회전이 되지 않도록

public class CharacterController : MonoBehaviour
{
    [SerializeField] private float moveSpeed;

    private bool movingLeft = true;
    private bool firstInput = true;

    private void Update()
    {
        if(GameManager.instance.gameStarted)
        {
            Move();
            CheckInput();
        }
    }

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

    private void CheckInput()
    {
        // if first input then ignore
        if (firstInput)
        {
            firstInput = false;
            return;
        }

        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개의 댓글