If I remove this code, my game functions fine, but it doesn’t seem to work even though I followed a tutorial D:
(A runtime error)
To be precise, this is the message log:
NullReferenceException: Object reference not set to an instance of an object
HealthBar.SetMaxHealth (System.Int32 health) (at Assets/HealthBar.cs:17)
PlayerHealth.Start () (at Assets/PlayerHealth.cs:13)
That error happens when you haven’t assigned a value to your fields. In this case, your “healthBar” and “slider” fields. To assign those values you need to drag the appropriate objects from your scene into those fields in the inspector for your script.
Expect to see this error a LOT. It’s easily the most common thing to do when working. Learn how to fix it rapidly. It’s easy. See the above link for more tips.