- Home /
XP Lamp script not working
my level up script is working but my xp lamp isnt working here is the basic level up script:
var XP = 0;
var NeededXP = 100;
//add a function OnGUI
if(XP == NeededXP);
if(XP == 100)
print("Level One Has Been Reached");
and here is my XP Lamp script:
@script RequireComponent(LevelScript);
var XP = 100;
function OnCollisionEnter(collision : Collision){
XP += 100;
}
Answer by TurboHermit · Nov 02, 2012 at 12:52 PM
There's two ways to approach this. The easy one is to make the variable XP a static variable, meaning it's a single variable accessible from every script. Just replace var XP = 0; with static var XP = 0; and remove var XP = 0; from your Lamp script.
The other one is a bit more technical and requires some knowledge of scripting, but that can wait. See if this works first.
thank you but when i walk into it im not rewarded with the 100 points
Answer by Rydrako · Nov 02, 2012 at 01:01 PM
Well your Lamp script is only adding 100 to the XP variable on the script. You didn't get your LevelScript's XP variable. First make the XP variable on the level up script a static:
static var XP = 0;
Now get rid of your XP variable in the lamp script and make a call to get the LevelScript's XP variable so it should look like this:
@script RequireComponent(LevelScript);
function OnCollisionEnter(collision : Collision){
LevelScript.XP += 100;
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613083224im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
First person controller prefab collision 1 Answer
Complete Level Script 1 Answer
Creating a level from a textfile 0 Answers
FPSPlayer script from FPS tutorial won't work... 0 Answers
Loading a level on contact 2 Answers