-= makes no sense in the context. And the compiler is telling you so.
-= will subtract the right hand value from the left hand value and set the left hand value to the result. In this case you are declaring a variable, and using -= on the same line.
here is what I use to affect another classes variable, I hope this helps.
public class FireBall : MonoBehaviour {
public int fireballDMG = 8;
public float speed = 15;
void Update ()
{
transform.Translate(0, 0, speed * Time.deltaTime);
}
void OnCollisionEnter(Collision otherObject)
{ //compares the name of the object to the string
if(otherObject.gameObject.name=="Boss")
{
//calls the function TakeDamage from the otherObject,passing the int and won't break the game if it isn't recieved
//function is case sensitive
SendMessage("TakeDamage", fireballDMG, SendMessageOptions.DontRequireReceiver);
}
}
}
public class BossScript : MonoBehaviour
{
int Health = 100, maxHealth = 100, Mana = 100, maxMana = 100;
GUIText healthText, manaText;
void Update()
{
manaText.text = Mana + "/" + maxMana;
healthText.text = Health + "/" + maxHealth;
if (Mana <= 0)
Mana = 0;
if (Health <= 0)
Health = 0;
if (Health >= maxHealth)
Health = maxHealth;
if (Mana >= maxMana)
Mana = maxMana;
}
// the function that is called from the sendMessage function uses local int Health
void TakeDamage(int damageTaken)
{
Health -= damageTaken;
}
}
Sending Messages can be useful because you don’t need a global variable.