new poster and new to stack exchange. I apologise if this has been answered but i am unable to find a solution sifting through the posts here.
I am getting a null reference exception on a very basic health bar script.
HealthBar script:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class HealthBars : MonoBehaviour {
public GameObject pug;
private Animator animator;
public Slider healthBar;
public Slider waterBar;
public Slider poopBar;
public Slider weeBar;
public Slider foodBar;
public static int health = 100;
public static int wee = 0;
public static int food = 25;
public static int poop = 0;
public static int water = 50;
// Use this for initialization
void Start()
{
InvokeRepeating("ReduceFood", 1, 1);
InvokeRepeating("WaterDrain", 1, 1);
}
// Update is called once per frame
void Update ()
{
}
void ReduceFood()
{
food = food - 5;
foodBar.value = food;
}
void WaterDrain()
{
water = water - 2;
waterBar.value = water;
}
I have the script attached to an empty GameObject. It drains the food once then throws the exception?