Hi, I keep getting null reference on this code! The funny thing is, it was working fine unity today morning, and when I tired playing it later without changing any code, it now throws a null reference. I have stated the variable/value in update, and then updated the slider value in late update, but it still throws a null reference. I have tried different ways, but it doesn't work. Code (CSharp): public Slider HealthSlider; [HideInInspector] public float Health; private GameObject Warden; public BlightBehaviours BlightBehaviours; void Start() { Warden = GameObject.Find("BlightWarden"); } private void Update() { Health = BlightBehaviours.Hitpoints; } // Update is called once per frame void LateUpdate() { HealthSlider.value = Health; // this part throws a null reference, it was working fine before! } public void DestroySlider() { Destroy(gameObject); }
Ensure that HealthSlider has been assigned in the inspector. Also check that you haven't accidentally added a second copy of your script somewhere (search t:<scriptname>) in the hierarchy search.
I have checked that HealthSlider is in the correct place and there is no duplicate script, but it still throws a null reference exception :|