Taking Damage

var FireballDMG : int = 8;
var bulletSpeed : float = 15;

function Update ()

{
    transform.Translate(0, 0, bulletSpeed * Time.deltaTime);
    }     
    
    function OnCollisionEnter(collision : Collision){
    	if(collision.gameObject.CompareTag("Boss")){
    	var curHealth -= FireballDMG;
        }
    }

okay so i have that on my fireball prefab but unity is telling me unexpected token “-=”? and here is my object script taking the damage.

public var curHealth : int = 100;
var maxHealth : int = 100;
var healthtext : GUIText;
public var curMana : int = 100;
var maxMana : int = 100;
var manatext : GUIText;

function Update () {

	manatext.text = curMana + " / " + maxMana;

	if(curMana < 0 ) {
		curMana = 0;
	}

	if(curMana > 100) {
		curMana = 100;
	}
	
	healthtext.text = curHealth + " / " + maxHealth;

	if(curHealth < 0 ) {
		curHealth = 0;
	}

	if(curHealth > 100) {
		curHealth = 100;
	}
}

-= 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.

You can resolve this by using:

scriptToTakeDamage.curHealth -= FireballDMG;

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.