Okay so I have two scripts, one is EnemyDamageReceiver.js, and I have this bit of code for it.
if (hitPoints <= 0.0) {
testexp.exp+=15;
// Start emitting particles
}
The other script is testexp.js and this is the code it contains.
static var exp : int = 0;
var level : int = 1;
var maxLevel : int = 100;
var expNeeded : int = 150;
var expIncrement : int = 2;
var guiTextExp : GUIText;
function Update(){
if(exp >= expNeeded){
expNeeded = expNeeded * expIncrement;
level++;
}
Debug.Log(exp);
Debug.Log(level);
guiTextExp.text = "Experience : "+ exp+ " | " + "Experience Needed : " + expNeeded + " | " +"Current Level :" + level;
}
Basically when i kill these enemies, i want it to add 15 on to the int exp. But it doesnt update the amount of exp whenever I kill something. Can anyone see why? Any advice would be very helpful.
How do you set the 'testexp' variable? Why is 'exp' a static? If you add a Debug.Log just before the call to update test expo.exp, does it print?
– HuacanachaYeah prints zero.
– cwaite84Also it is a static because I access it from another class. Guess I forgot to show this bit of code for the first script:
– cwaite84var EXP : testexp; var script = GameObject.Find("Player").GetComponent(testexp);That is how I declare the testexp. I assume my basc logic is correct, but its the right track wrong train in this situation.Static means you have a single variable for ALL instances of that script. If you use the script on multiple objects they will share this variable. Static is NOT how how you access a variable from another script. You get the script from the game objects you're interesting in and access the variable through that. In your case you could do: script.exp; You probably need to make the type of the 'script' variable 'testexp' for this to work. I'm not 100% sure as I don't use Unityscript/JavaScript.
– Huacanacha