NullReference异常Unity

时间:2017-04-17 23:13:55

标签: c# unity3d

新的海报和新的堆栈交换。如果这个问题得到了解答,我很抱歉,但我无法找到解决这些帖子的解决方案。

我在一个非常基本的健康栏脚本上得到一个空引用异常。

HealthBar脚本:

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;
    } 

我将脚本附加到空GameObject。它排出食物一次然后抛出异常?

0 个答案:

没有答案