Hello,
I’m trying to keep a recored of how many turrets the player places down on the scene.
The recored is displayed in the main menu.
So what I have is a JS called ‘TurretStats’ which is on my main menu. On my turrets I have a script called ‘Left Menu’ which I want to talk to the TurretStats’s arrays.
So:
TurretStats -
static var MostUsedTurret : int[];
function Update(){
print("Recored: "+MostUsedTurret[0]+MostUsedTurret[1]+MostUsedTurret[2]);
}
Then in the game scene, I have LeftMenu (which is attached to my turrets - so when instantiated, I want it to add a +1 to the array in turret stats to a specific element.
Bear in mind that I have 3 turrets (each with a unique LeftMenu script).
So in Turret 1 - Left Menu:
function Start(){
TurretStats.MostUsedTurret[0] ++;
}
In Turret 2 - Left Menu2:
function Start(){
TurretStats.MostUsedTurret[1] ++;
}
In Turret 3 - Left Menu3:
function Start(){
TurretStats.MostUsedTurret[2] ++;
}
The problem is, is that it doesn’t seem to be added the variables to the array, I keep getting a null exception.
What am I doing wrong, and is there a better way to do this?
Thanks
You’ve created the variable to point to the array, but you aren’t new’ing an array to put in it.