Seperate GetMovementVectorNormalized into a seperate class

This commit is contained in:
BuyMyMojo 2023-02-26 02:25:40 +11:00
parent 96eb06023d
commit cf2ddd9ba6
3 changed files with 45 additions and 20 deletions

View file

@ -6,31 +6,13 @@ public class Player : MonoBehaviour
{
[SerializeField] private float moveSpeed = 7f;
[SerializeField] private GameInput gameInput;
private bool isWalking;
private void Update()
{
Vector2 inputVector = new Vector2(0,0);
if (Input.GetKey(KeyCode.W))
{
inputVector.y = +1;
}
if (Input.GetKey(KeyCode.S))
{
inputVector.y = -1;
}
if (Input.GetKey(KeyCode.A))
{
inputVector.x = -1;
}
if (Input.GetKey(KeyCode.D))
{
inputVector.x = +1;
}
inputVector = inputVector.normalized;
Vector2 inputVector = gameInput.GetMovementVectorNormalized();
Vector3 moveDir = new Vector3(inputVector.x, 0f, inputVector.y);
transform.position += moveDir * moveSpeed * Time.deltaTime;