Move the movement code to a seperate function
This commit is contained in:
parent
cfa7b830d7
commit
d216580bca
1 changed files with 14 additions and 7 deletions
|
@ -11,6 +11,16 @@ public class Player : MonoBehaviour
|
|||
private bool isWalking;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
HandleMovement();
|
||||
}
|
||||
|
||||
public bool IsWalking()
|
||||
{
|
||||
return isWalking;
|
||||
}
|
||||
|
||||
private void HandleMovement()
|
||||
{
|
||||
Vector2 inputVector = gameInput.GetMovementVectorNormalized();
|
||||
|
||||
|
@ -32,7 +42,8 @@ public class Player : MonoBehaviour
|
|||
if (canMove)
|
||||
{
|
||||
moveDir = moveDirX;
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
// Cannot move on X so attempt to move on Z
|
||||
Vector3 moveDirZ = new Vector3(0, 0, moveDir.z).normalized;
|
||||
|
@ -40,7 +51,8 @@ public class Player : MonoBehaviour
|
|||
if (canMove)
|
||||
{
|
||||
moveDir = moveDirZ;
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
// Cannot move at all
|
||||
}
|
||||
|
@ -57,9 +69,4 @@ public class Player : MonoBehaviour
|
|||
transform.forward = Vector3.Slerp(transform.forward, moveDir, Time.deltaTime * rotateSpeed);
|
||||
}
|
||||
|
||||
public bool IsWalking()
|
||||
{
|
||||
return isWalking;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Reference in a new issue