
처음 눌렀을때 방향 회전이 되지 않도록
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);
}
}
}