I’m tearing my hair out over this one! I’ve created a script called HealthDisplay.cs and added it to my HealthDisplay TextMeshPro object. This didn’t work (gave me a NullReferenceException) so I tried commenting it out and just printing the value (as in the below) which also didn’t work. I added the print in the Start() method as part of my debugging though, and that print seems to work fine - so something’s going wrong between the Start and the first Update? Any ideas?!
using UnityEngine;
using System;
using RPG.Attributes;
namespace RPG.Stats
{
public class HealthDisplay : MonoBehaviour
{
Health health = null;
void Start() {
Health health = GameObject.FindWithTag("Player").GetComponent<Health>();
print(String.Format("{0}%", health.GetPercentage()));
}
void Update() {
print(String.Format("{0}%", health.GetPercentage()));
//GetComponent<TextMeshProUGUI>().text = String.Format("{0}%", health.GetPercentage());
}
}
}