can someone explain me how to create a simple scoreboard that when my player hit whatever gameodject add one point
1 Answer
1The simplest way to to this is with an OnGUI function and a public variable, in a script that you attach to an empty gameobject in your scene:
using UnityEngine;
using System.Collections;
public class scoreboard: MonoBehaviour {
public int currentscore;
void OnGUI() {
GUILayout.Label("Score:");
GUILayout.Label(currentscore);
}
}
Every time you need to change the score, in the calling script, you do something like:
GameObject.Find("scoreboardobject").GetComponent<scoreboard>().currentscore++;
which you can of course cache to avoid doing the .Find every time your score changes.