Seperate GetMovementVectorNormalized into a seperate class
This commit is contained in:
parent
96eb06023d
commit
cf2ddd9ba6
3 changed files with 45 additions and 20 deletions
32
Assets/Scripts/GameInput.cs
Normal file
32
Assets/Scripts/GameInput.cs
Normal file
|
@ -0,0 +1,32 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class GameInput : MonoBehaviour
|
||||
{
|
||||
public Vector2 GetMovementVectorNormalized()
|
||||
{
|
||||
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;
|
||||
|
||||
return inputVector;
|
||||
}
|
||||
}
|
Reference in a new issue