var score = 0;
function OnTriggerEnter( other : Collider ) {
Debug.Log("OnTriggerEnter() was called");
if (other.tag == "Coin") {
Debug.Log("Other object is a coin");
score += 5;
Debug.Log("Score is now " + score);
Destroy(other.gameObject);
}
}
function OnGUI () {
GUI.Label (Rect (10, 10, 100, 20), score.ToString()); }
At now the script print on my screen "5" if i collect 1 coin.
I want to print "Score:5"
You can concatenate a string using the "+" operator. Whenever there's a string and you use `+`, other arguments are automatically converted to string unless you put them in parentheses. So