- Home /
 
Operator '+' cannot be used
SCRIPT
 #pragma strict
 
 var currentHealth : float = 100;
 var maxHealth : int = 100;
 
 var barLength = 0.0;
 
 function Start()
 {
     barLength = Screen.width / 8;
 }
 
 function Update()
 {
     AdjustCurrentHealth (0);
 }
 
 function OnGUI()
 {
     //Icons for GUI
     GUI.Box(Rect(5, 10, 55, 25), "Health");
     
     //Health
     GUI.Box(Rect(65, 10, 55, 25), currentHealth.ToString("0") + "/" + maxHealth);
 }
 
 function AdjustCurrentHealth (adj)
 {
     currentHealth += adj;
     
     if(currentHealth >= maxHealth)
     {
         currentHealth = maxHealth;
     }
     
     if(currentHealth <= 0)
     {
         currentHealth = 0;
     }
 }
 
               ERROR
Operator '+' cannot be used with a left hand side of type 'float' and a right hand side of type 'Object'.
Can someone tell me what's wrong with this line
 currentHealth += adj;
 
               What should I do?
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by getyour411 · Mar 22, 2014 at 08:21 PM
Modify it to (adj : float) or whatever the right syntax is for JS
Your answer