Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma strict
- enum abilityNames {
- Dash,
- Heal,
- SpeedBoost,
- }
- class AbilitySlot {
- var playerO : GameObject;
- var cooldown : float;
- var isOnCooldown : boolean = false;
- var abilityInSlot : abilityNames;
- private var abilName : abilityNames;
- function SetAbility(ability : abilityNames) {
- playerO = GameObject.FindWithTag("Player"); // need to initialise playerO
- abilityInSlot = ability;
- SetCooldown();
- }
- function SetCooldown() {
- switch(abilityInSlot) {
- case abilName.Dash:
- cooldown = 30;
- break;
- case abilName.Heal:
- cooldown = 45;
- break;
- case abilName.SpeedBoost:
- cooldown = 60;
- break;
- default:
- Debug.Log("Couldn't find ability. This shouldn't happen");
- cooldown = 0;
- break;
- }
- }
- function Use() : IEnumerator{
- Debug.Log("in Use()");
- if(!isOnCooldown) {
- isOnCooldown = true;
- Debug.Log("not on cd");
- switch(abilityInSlot) {
- case abilName.Dash:
- Abilities.Dash(playerO);
- break;
- case abilName.SpeedBoost:
- Abilities.SpeedBoost(playerO);
- break;
- case abilName.Heal:
- Abilities.Heal(playerO);
- break;
- }
- yield WaitForSeconds(cooldown);
- isOnCooldown = false;
- }
- else {
- Debug.Log("On cooldown");
- }
- return;
- }
- }
- // Script Init & Updates
- var abilityQ : AbilitySlot = new AbilitySlot();
- var abilityE : AbilitySlot = new AbilitySlot();
- var abilityR : AbilitySlot = new AbilitySlot();
- private var abilName : abilityNames;
- function Start () {
- abilityQ.SetAbility(abilName.Dash);
- abilityE.SetAbility(abilName.Heal);
- abilityR.SetAbility(abilName.SpeedBoost);
- }
- function Update () {
- if(Input.GetKeyDown(KeyCode.Q)) {
- abilityQ.Use();
- }
- if(Input.GetKeyDown(KeyCode.E)) {
- abilityE.Use();
- }
- if(Input.GetKeyDown(KeyCode.R)) {
- Debug.Log("R is down");
- UpUse();
- //abilityR.Use();
- Debug.Log("out of Use()");
- }
- }
- function UpUse() {
- Debug.Log("test");
- }
- // Abilities
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement