Hey everyone,
after trying to find out what is wrong for more than two days I need to ask.
public class CharacterStats:MonoBehaviour
{
public float maxHealth = 10.0f;
public float health = 10.0f;
public Slider healthSlider;
void Awake()
{
Debug.Log(healthSlider.name);
}
I have the Slider component added in editor
![]()
but I still get an error:
NullReferenceException: Object reference not set to an instance of an object
CharacterStats.Awake () (at Assets/Scripts/CaracterLogic/CharacterStats.cs:18)
And whats weird on it? I can work with the Slider component. The code I
private void OnGUI()
{
healthSlider.value = health / maxHealth;
}
does what is should (health is decresing as it should) and does not throw the error. But when I try to remove the debug log from aware fuction, it is thorown in the OnGUI.
My guess is that I must have broken the project somehow but I have no idea how to fix it.
Please help!
Thanks