Cooldowns, SkillHandler modification
Implementation of cooldowns for skills and spells, made dependency on monoBehaviour for SkillHandler(future implementation of update, fixed update possible)
This commit is contained in:
@@ -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<PlayerSkillTree.Skills, float> cooldowns;
|
||||
private Dictionary<PlayerSkillTree.Skills, float> cooldownsActivated;
|
||||
|
||||
public bool IsDashing() { return isDashing; }
|
||||
|
||||
public PlayerSkillHandler(float dashSpeed, float dashDuration)
|
||||
{
|
||||
this.dashSpeed = dashSpeed;
|
||||
this.dashDuration = dashDuration;
|
||||
public void Start()
|
||||
{
|
||||
|
||||
cooldowns = new Dictionary<PlayerSkillTree.Skills, float>();
|
||||
cooldownsActivated = new Dictionary<PlayerSkillTree.Skills, float>();
|
||||
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];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user