I have a Skill base class and 2 separate Skill classes that inherit from the Class Skill. Each skill has its own SkillCoolDown
value. I set the CoolDownManager
Class that is visualising the cooldowns for the skills, but I don't understand how to set the SkillCoolDown
value to the manager which is different for each skill. Would appreciate the help.
public class Skill
{
private string skillName;
private int skillDamage;
private string skillDescription;
private int skillCoolDown;
public string SkillName {get;set;}
public int SkillDamage {get;set;}
public string SkillDescription {get;set;}
public int SkillCoolDown {get;set;}
public Skill () {}
}
public class CoolDownManager : MonoBehaviour
{
public Skill skill;
private Stopwatch cooldown;
private Button button;
private Image fillImage;
private int skillCoolDown;
public void OnSkillUse(Button btn) {
skill = new Skill(); // HERE THE VALUE SkillCoolDown SHOULD BE IMPLEMENTED AND I WANT SOMEHOW TO SHOW WHICH SKILL HAS BEEN USED.
button = btn.GetComponent<Button>();
fillImage = btn.transform.GetChild(0).gameObject.GetComponent<Image>();
btn.interactable = false;
fillImage.fillAmount = 1;
cooldown = new Stopwatch();
cooldown.Start();
StartCoroutine(CoolDownAnimation());
}
private IEnumerator CoolDownAnimation() {
while(cooldown.IsRunning && cooldown.Elapsed.TotalSeconds < skill.SkillCoolDown) {
fillImage.fillAmount = ((float)cooldown.Elapsed.TotalSeconds / skill.SkillCoolDown);
yield return null;
}
fillImage.fillAmount = 0;
button.interactable = true;
cooldown.Stop();
cooldown.Reset();
}
}
And here is example of the Skill class from where the value SkillCoolDown
should be passed.
public class BasicAttack : Skill
{
public BasicAttack()
{
SkillCoolDown = 2;
}
}
Aucun commentaire:
Enregistrer un commentaire