From d216580bcaa375f417aeb6b06ba69ded5c129ece Mon Sep 17 00:00:00 2001 From: BuyMyMojo Date: Tue, 28 Feb 2023 02:20:23 +1100 Subject: [PATCH] Move the movement code to a seperate function --- Assets/Scripts/Player.cs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/Assets/Scripts/Player.cs b/Assets/Scripts/Player.cs index 45ef764..e6e9e94 100644 --- a/Assets/Scripts/Player.cs +++ b/Assets/Scripts/Player.cs @@ -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; - } - }