diff --git a/3D blobici/Assets/Prefabs/PlayerContainer.prefab b/3D blobici/Assets/Prefabs/PlayerContainer.prefab index 0e32f08..dc1c0af 100644 --- a/3D blobici/Assets/Prefabs/PlayerContainer.prefab +++ b/3D blobici/Assets/Prefabs/PlayerContainer.prefab @@ -569,6 +569,7 @@ GameObject: - component: {fileID: 1781483820777133190} - component: {fileID: 8149587721611830724} - component: {fileID: 6867876445951065937} + - component: {fileID: 3082501562675303841} m_Layer: 6 m_Name: Player m_TagString: Player @@ -672,6 +673,21 @@ MeshCollider: m_Convex: 1 m_CookingOptions: 30 m_Mesh: {fileID: 0} +--- !u!114 &3082501562675303841 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 3653993672432327505} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: bf963ec282f9eff40b50054039952aee, type: 3} + m_Name: + m_EditorClassIdentifier: + dashCooldown: 2 + dashSpeed: 15 + dashDuration: 0.25 --- !u!1 &4992829604954765258 GameObject: m_ObjectHideFlags: 0 diff --git a/3D blobici/Assets/Scripts/Player/PlayerMovement.cs b/3D blobici/Assets/Scripts/Player/PlayerMovement.cs index feb20a5..2fafc51 100644 --- a/3D blobici/Assets/Scripts/Player/PlayerMovement.cs +++ b/3D blobici/Assets/Scripts/Player/PlayerMovement.cs @@ -21,7 +21,7 @@ public class PlayerMovement : MonoBehaviour private void Awake() { PlayerSkills = PlayerSkillTree.Instance; - playerSkillHandler = new PlayerSkillHandler(dashSpeed, dashDuration); + playerSkillHandler = GetComponent(); } void Start() @@ -31,7 +31,7 @@ public class PlayerMovement : MonoBehaviour private void Update() { - if (Input.GetKeyDown(KeyCode.Space)) + if (Input.GetKeyDown(KeyCode.Space) && !playerSkillHandler.IsOnCooldown(PlayerSkillTree.Skills.Dash)) { /* Get the input for horizontal and vertical movement */ float moveX = Input.GetAxisRaw("Horizontal"); diff --git a/3D blobici/Assets/Scripts/Player/PlayerSkillHandler.cs b/3D blobici/Assets/Scripts/Player/PlayerSkillHandler.cs index 6f03c89..86efa73 100644 --- a/3D blobici/Assets/Scripts/Player/PlayerSkillHandler.cs +++ b/3D blobici/Assets/Scripts/Player/PlayerSkillHandler.cs @@ -2,19 +2,26 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; -public class PlayerSkillHandler +public class PlayerSkillHandler: MonoBehaviour { - private float dashSpeed; - private float dashDuration; + [Header("Dash stats")] + [SerializeField] private float dashCooldown; + [SerializeField] private float dashSpeed; + [SerializeField] private float dashDuration; private bool isDashing = false; + private Dictionary cooldowns; + private Dictionary cooldownsActivated; + public bool IsDashing() { return isDashing; } - public PlayerSkillHandler(float dashSpeed, float dashDuration) - { - this.dashSpeed = dashSpeed; - this.dashDuration = dashDuration; + public void Start() + { + + cooldowns = new Dictionary(); + cooldownsActivated = new Dictionary(); + AssignCooldowns(); } public IEnumerator DashCoroutine(CharacterController controller, Vector3 direction) @@ -27,8 +34,37 @@ public class PlayerSkillHandler controller.Move(dashSpeed * Time.deltaTime * direction); yield return null; // wait one frame } + handleCooldownTimer(PlayerSkillTree.Skills.Dash); isDashing = false; // just for now. maybe will be removed Physics.IgnoreLayerCollision(6, 7, false); // enable collisions between player and enemies } + private void handleCooldownTimer(PlayerSkillTree.Skills skill) + { + if(!cooldownsActivated.ContainsKey(skill)) + { + cooldownsActivated.Add(skill, Time.time); + } + else + { + cooldownsActivated[skill] = Time.time; + } + + } + + private void AssignCooldowns() + { + // handle Dash stats + cooldowns.Add(PlayerSkillTree.Skills.Dash, dashCooldown); + cooldownsActivated.Add(PlayerSkillTree.Skills.Dash, Time.time - dashCooldown); + } + + public bool IsOnCooldown(PlayerSkillTree.Skills skill) + { + Debug.Log("cooldown time: " + (Time.time - cooldownsActivated[skill])); + Debug.Log("skill cooldown: " + cooldowns[skill]); + return !cooldowns.ContainsKey(skill) || !cooldownsActivated.ContainsKey(skill) + ? false + : Time.time - cooldownsActivated[skill] < cooldowns[skill]; + } }