Hey Again UnityAnswers.
I’m once again facing a weird problem. I want to display my currentHealth variable on the healthText.text HUD element. Now, my currentHealth is an integer. I’ve tried converting it to a string before changing the UI using ToString();, but this only returns a NullReferenceException error. Now, i know that NullReferenceException means that currentHealth is null, but in Awake() i set currentHealth to startingHealth, which is 100…
Here’s my code. Thanks in advance!
public void TakeDamage (int amount)
{
// Set the damaged flag so the screen will flash.
damaged = true;
currentHealth -= amount;
currentHealth.ToString ();
// Set the HUD health string's value to the current health
healthText.text = currentHealth;
if(currentHealth <= 0 && !isDead)
{
// ... it should die.
Death ();
}
}