using System; using UnityEngine; public class PlayerMove : MonoBehaviour { [SerializeField] private float speed; [SerializeField] private Rigidbody rb; [SerializeField] private Vector3 StartPos; bool vertical; bool horizontal; private void Start() { rb = GetComponent(); } void Update() { float horizontalInput = Input.GetAxis("Horizontal"); float verticalInput = Input.GetAxis("Vertical"); horizontalInput = Mathf.Round(horizontalInput); verticalInput = Mathf.Round(verticalInput); Vector3 moveDirection; if (horizontalInput != 0 && horizontal == true) { vertical = false; moveDirection = new Vector3(horizontalInput,0, 0); moveDirection.Normalize(); } else if (verticalInput != 0 && vertical == true) { horizontal = false; moveDirection = new Vector3(0, 0, verticalInput); moveDirection.Normalize(); } else { moveDirection = new Vector3(0, 0, 0); horizontal = true; vertical = true; } transform.Translate(moveDirection * speed * Time.deltaTime, Space.World); } public void Reset() { this.transform.position = StartPos; } }