I'm making a score counter and letting other objects access it with Get and Set functions.
The Inc(n) function works and "score" keeps going up, but GetString() shows "score" at 0. Why is that happening?
#pragma strict
private var score:int;
function Start () {
score = 0;
}
function Inc(a:int) {
print("inc added "+a+" to score.");
score = score+a;
print("Score is now "+score+".");
}
function GetString():String {
print("Sending score as "+score);
return score.ToString();
}
function Get():int {
return score;
}
function Set(a:int) {
score = a;
}
Additional - here is a shortened version of the script that uses the Inc(n) function...
#pragma strict
// abridged code
var scoreManager:ScoreManager; // This is so you can send stuff to the score manager.
// abridged code
function OnTriggerEnter(col:Collider)
{
for (a=0; a
↧