From e6006b59ee8aa6459d30d24b20500aceb9fca4fc Mon Sep 17 00:00:00 2001 From: Zidane <13521163@std.stei.itb.ac.id> Date: Fri, 10 May 2024 09:52:24 +0700 Subject: [PATCH] add statistics to movement --- Assets/Scripts/PlayerR/PlayerMovement.cs | 10 ++++++++++ Assets/Scripts/Statistic/GeneralStatistics.cs | 2 -- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Assets/Scripts/PlayerR/PlayerMovement.cs b/Assets/Scripts/PlayerR/PlayerMovement.cs index d1a154a..65c925d 100644 --- a/Assets/Scripts/PlayerR/PlayerMovement.cs +++ b/Assets/Scripts/PlayerR/PlayerMovement.cs @@ -18,10 +18,15 @@ public class PlayerMovement : MonoBehaviour, CheatListener private Vector3 playerVelocity; private PlayerState playerState = PlayerState.OnGround; private float allowableSpeed = 0; + + private GameObject _generalStatisticsGo; + private GeneralStatistics _generalStatistics; private void Start() { characterController = GetComponent<CharacterController>(); + _generalStatisticsGo = GameObject.FindGameObjectWithTag("GeneralStatistics"); + _generalStatistics = _generalStatisticsGo?.GetComponent<GeneralStatistics>(); } public void MovePlayer(Vector2 input, Animator animator) @@ -48,6 +53,11 @@ public class PlayerMovement : MonoBehaviour, CheatListener { playerState = PlayerState.OnGround; } + + if (_generalStatistics != null) + { + _generalStatistics.TravelDistance += dir.magnitude; + } } public void JumpPlayer() diff --git a/Assets/Scripts/Statistic/GeneralStatistics.cs b/Assets/Scripts/Statistic/GeneralStatistics.cs index 8fa32d3..f199e65 100644 --- a/Assets/Scripts/Statistic/GeneralStatistics.cs +++ b/Assets/Scripts/Statistic/GeneralStatistics.cs @@ -89,6 +89,4 @@ public class GeneralStatistics : MonoBehaviour killdeath = totalKillCount / totalDeathCount; } - - } \ No newline at end of file -- GitLab