public static variable not showing on UI Text
Hi guys,
This is a very weird thing which is happening, basically I am trying to print the health on a UI however it is not being displayed. I have try to test with a normal integer and it did work.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class PlayerHealth : MonoBehaviour {
public static int health = 1000;
Text healthTxt;
// Use this for initialization
void Start () {
healthTxt = GameObject.Find("healthTxt").GetComponent<Text>();
}
// Update is called once per frame
void Update () {
healthTxt.text = "Health: " + health;
if(health <= 0)
{
SceneManager.LoadScene(0);
}
}
}
Thanks!
Comment
Answer by Hawk690 · May 10, 2017 at 11:21 PM
Hi thanks for your interest. I just fixed it! I knew it was a stupid mistake.
Basically all I had to do was to tick "Best Paragraph" from the Text component of the Text object!
Your answer

Follow this Question
Related Questions
How do I reset a static gameObject? 1 Answer
How to make a crosshair in the middle of the screen? 0 Answers
Grey screen when i open unity 0 Answers