
목표 : 터치에 따라 플레이어 방향 회전하기
- 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);
}
}
}