- Home /
activating object only on true
so what I'm after is if current mana 5 can cast spell. kinda new to programming and any help would be appreciated thanks. if you need my whole code let me know :D
this is my little attempt at what I am after.
bool activateShield = false; public float current mana = 100f; public GameObject Shield;
             {
         if (currentMana >= 5)
             activateShield = true;
         else if (currentMana <= 5)
             activateShield = false;
                                                                                                                                                
         if (Input.GetKeyDown (KeyCode.LeftShift))
             activateShield = true;                                
         Shield.SetActive (true);
         if (Input.GetKeyUp (KeyCode.LeftShift))
             activateShield = false;
         Shield.SetActive (false);
     }
 }
}
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by justinkatic · Sep 27, 2017 at 05:49 AM
nm worked it out ended up using a else if statement instead and worked great :D
     {
         
         if (Input.GetKeyDown (KeyCode.LeftShift) && currentMana >= 0)
             Shield.SetActive (true);
         else if
             (currentMana <= 0)
             Shield.SetActive (false);
         
         if (Input.GetKeyUp (KeyCode.LeftShift))
         Shield.SetActive (false);
     }
 }
}
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                