global variable problem?

Hello. I know this is a common problem and I have looked at the doc and other posts but I am having a problem.
In this script I am defining a variable for the score multiplier in my game. This script is called “Stats” and is the “Player” game object.

var Mul = 1;
function OnTriggerEnter (other : Collider) {

    if (other.gameObject.CompareTag ("Mul")) {
        Destroy (other.gameObject);
        Mul += 1;
    }
}

In this script I am defining the variable for the game’s score (the score added will be 100 multiplied by whatever the current Mul value is). This script is called “Projectile” and is in the “Projectile” game object.

static var Score = 0;
var Stats.Mul = 1;

function OnTriggerEnter (other : Collider) {
    if (other.gameObject.CompareTag ("Enemy")) {
        Destroy (gameObject);
        Destroy (other.gameObject);

        Score += 100*Mul;
    }
}

I keep getting an error about an unexpected token referencing the “.” in the second line of the “projectile” script. How can I fix this? Thank you.

I have also tried changing “Score += 100Mul;" to this "Score +=(100Stats.Mul);” and I do not get any errors, but it does not work the way it is supposed to.

“var Stats.Mul = 1” is incorrect. I’m assuming you want “Mul” to exist as a global on a “Stats” script? In that case, you would want:

static var Score = 0;

function OnTriggerEnter (other : Collider) {
    if (other.gameObject.CompareTag ("Enemy")) {
        Destroy (gameObject);
        Destroy (other.gameObject);

        Score += 100*Stats.Mul;
    }
}

If not, I’m hoping this can point you in the right direction.

That worked, thanks :slight_smile: