From 91d53ac010f9e4af9510353c4d8cb10e93e0b800 Mon Sep 17 00:00:00 2001 From: Giovani Date: Sun, 2 Feb 2020 15:26:50 -0500 Subject: [PATCH] stamina and health fix --- Assets/Scenes/LevelOne.unity | 3 ++- Assets/Scripts/Player.cs | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Assets/Scenes/LevelOne.unity b/Assets/Scenes/LevelOne.unity index e2c84f8..6da7db7 100644 --- a/Assets/Scenes/LevelOne.unity +++ b/Assets/Scenes/LevelOne.unity @@ -47979,7 +47979,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1671840916} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 14.5, y: -10.5, z: 0} + m_LocalPosition: {x: -9, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 1008122163} @@ -48096,6 +48096,7 @@ MonoBehaviour: coffeValuePercent: 10 bugStaminaDamagePercent: 15 hurtVelocity: 20 + fightSoundLength: 5 healthBar: {fileID: 367096170} staminaBar: {fileID: 1895829831} --- !u!95 &1671840923 diff --git a/Assets/Scripts/Player.cs b/Assets/Scripts/Player.cs index af0ef39..9500fed 100644 --- a/Assets/Scripts/Player.cs +++ b/Assets/Scripts/Player.cs @@ -18,6 +18,7 @@ public class Player : MonoBehaviour [SerializeField] private int coffeValuePercent = 10; [SerializeField] private int bugStaminaDamagePercent = 15; [SerializeField] private float hurtVelocity = 15f; + [SerializeField] private int fightSoundLength = 5; private int currentHealth; private int currentStamina; @@ -32,7 +33,7 @@ public class Player : MonoBehaviour private bool isMovementEnabled = true; private bool isFighting = false; private bool isHurt = false; - + private int fightSoundAccumalator = 0; private bool isPlayerHurt = false; private void Start() @@ -116,7 +117,6 @@ public class Player : MonoBehaviour private void Hurt() { - currentHealth = 3; // TODO: REMOVE! currentHealth -= currentHealth > 0 ? 1 : 0; healthBar.size = new Vector2(1.5f * currentHealth, this.healthBar.size.y); @@ -143,7 +143,6 @@ public class Player : MonoBehaviour isHurt = false; }; - PlayFightSound(); HandleAnimations(); } @@ -264,7 +263,15 @@ public class Player : MonoBehaviour { if (isFighting && !isPlayerHurt) { - SoundManagerScript.PlaySound(GetRandomFightClipName()); + if (fightSoundAccumalator >= fightSoundLength) + { + SoundManagerScript.PlaySound(GetRandomFightClipName()); + fightSoundAccumalator = 0; + } + else + { + fightSoundAccumalator++; + } } } @@ -304,6 +311,6 @@ public class Player : MonoBehaviour public float GetStaminaDifficultyFactor() { - return currentStamina / (startStamina * 1f); + return Mathf.Clamp(currentStamina / (startStamina * 1f), 0.27f, 1); } }