Advertisement
Guest User

Untitled

a guest
Sep 17th, 2014
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #pragma strict
  2.  
  3. enum abilityNames {
  4.     Dash,
  5.     Heal,
  6.     SpeedBoost,
  7. }
  8.  
  9. class AbilitySlot {
  10.  
  11.     var playerO : GameObject;
  12.    
  13.     var cooldown : float;
  14.     var isOnCooldown : boolean = false;
  15.     var abilityInSlot : abilityNames;  
  16.     private var abilName : abilityNames;
  17.    
  18.     function SetAbility(ability : abilityNames) {
  19.    
  20.         playerO = GameObject.FindWithTag("Player"); // need to initialise playerO
  21.         abilityInSlot = ability;
  22.         SetCooldown();
  23.        
  24.     }
  25.    
  26.     function SetCooldown() {
  27.    
  28.         switch(abilityInSlot) {
  29.             case abilName.Dash:
  30.                 cooldown = 30;
  31.                 break;
  32.             case abilName.Heal:
  33.                 cooldown = 45;
  34.                 break;
  35.             case abilName.SpeedBoost:
  36.                 cooldown = 60;
  37.                 break;
  38.             default:
  39.                 Debug.Log("Couldn't find ability. This shouldn't happen");
  40.                 cooldown = 0;
  41.                 break;
  42.         }
  43.        
  44.     }
  45.    
  46.     function Use() : IEnumerator{
  47.         Debug.Log("in Use()");
  48.         if(!isOnCooldown) {
  49.             isOnCooldown = true;
  50.            
  51.             Debug.Log("not on cd");
  52.            
  53.             switch(abilityInSlot) {
  54.                 case abilName.Dash:
  55.                     Abilities.Dash(playerO);
  56.                     break;
  57.                 case abilName.SpeedBoost:
  58.                     Abilities.SpeedBoost(playerO);
  59.                     break;
  60.                 case abilName.Heal:
  61.                     Abilities.Heal(playerO);
  62.                     break;
  63.             }
  64.            
  65.             yield WaitForSeconds(cooldown);
  66.             isOnCooldown = false;
  67.         }
  68.         else {
  69.             Debug.Log("On cooldown");
  70.         }
  71.         return;
  72.     }
  73.    
  74. }
  75.  
  76.  
  77. // Script Init & Updates
  78.  
  79. var abilityQ : AbilitySlot = new AbilitySlot();
  80. var abilityE : AbilitySlot = new AbilitySlot();
  81. var abilityR : AbilitySlot = new AbilitySlot();
  82. private var abilName : abilityNames;
  83.  
  84. function Start () {
  85.    
  86.     abilityQ.SetAbility(abilName.Dash);
  87.     abilityE.SetAbility(abilName.Heal);
  88.     abilityR.SetAbility(abilName.SpeedBoost);
  89.    
  90. }
  91.  
  92. function Update () {
  93.  
  94.     if(Input.GetKeyDown(KeyCode.Q)) {
  95.         abilityQ.Use();
  96.     }
  97.     if(Input.GetKeyDown(KeyCode.E)) {
  98.         abilityE.Use();
  99.     }
  100.     if(Input.GetKeyDown(KeyCode.R)) {
  101.         Debug.Log("R is down");
  102.         UpUse();
  103.         //abilityR.Use();
  104.         Debug.Log("out of Use()");
  105.     }
  106.    
  107. }
  108.  
  109. function UpUse() {
  110.     Debug.Log("test");
  111. }
  112.  
  113.  
  114. // Abilities
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement