So, here's how it's done.
function addingExp(){
var level = gameObject.Find("Player").GetComponent(Level);
level.experience +=50;
}
Explanation:
gameObject.Find("Player")
Finds the object the script it attached to. Player is the name of the object, note that the name has to be in quotations.
GetComponent(Level)
Finds the name of the script.
level.experience +=50;
level is calling the variable that we just set above, experience is a variable within the script that were calling on in the code.
If you wanted to call a function from another script, it would be something like this...
function addingExp(){
var level = gameObject.Find("Player").GetComponent(Level);
level.experience +=50;
}
Explanation:
gameObject.Find("Player")
Finds the object the script it attached to. Player is the name of the object, note that the name has to be in quotations.
GetComponent(Level)
Finds the name of the script.
level.experience +=50;
level is calling the variable that we just set above, experience is a variable within the script that were calling on in the code.
If you wanted to call a function from another script, it would be something like this...
function addingExp(){
var level = gameObject.Find("Player").GetComponent(Level);
level.DoSomething();
}
Calling on different scripts is great for any game, especially for making a point system or creating something like an RPG to keep up with levels and everything.
you are jesus
ReplyDelete