I am struggling with this problem for quite a while now: I have this static class:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace Platformer;
{
public static class VarBoard
{
public static GameObject Player;
public static GameObject LevelGenerator;
public static GameObject PlayerHealthBar;
public static List <GameObject> AllEnemies = new List<GameObject> ();
public static List <GameObject> AllFriends = new List<GameObject> ();
}
}
This class stores all global Variables, so I can use them from various places in my project, like this:
using UnityEngine;
using System.Collections;
using Platformer;
public class HealthBar : MonoBehaviour
{
void Update{
this.GetComponent<RectTransform> ().sizeDelta = new Vector2 (VarBoard.Player.GetComponent<Character> ().health, 40);
}
}
I found this structure in this tutorial and it seemed to be a reasonable solution for me, but when I run the code I just get this
Exception: NullReferenceException: Object reference not set to an instance of an object
But as far as I understand, isn't it the purpose of a static class that you don't need instances of it? Or am I missing something here?