To those of you who are screaming at the screen telling Ben to use TextMeshPro (I did), here is what the few changes are to make it happen:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro; //IMPORTANT Change #1
public class ScoreBoard : MonoBehaviour {
[SerializeField] int scorePerHit = 12;
int score;
TextMeshPro textMeshScore; // Change #2
// Use this for initialization
void Start () {
textMeshScore = GetComponent<TextMeshPro>(); // Change #3
textMeshScore.text = "0";
}
public void ScoreHit()
{
score += scorePerHit;
textMeshScore.text = score.ToString();
}
}
The rest is the same.
And for all the idiots, like me, it doesn’t work as on screen ui…: Change the Canvas render mode to “Screen-Space - Camera”, set the camera as main camera and set the plane distance to something small like 1.