I have a game object: GameManager, that I want to access from all classes. I've set it in Start() to not be destroyed on load (here is my start function for gamemanager):
public void Start(){
DontDestroyOnLoad (this);
SaveLoad.Save ();
levelTimes = new float[20];
SaveLoad.Load ();
}
But, I can't seem to access it by using gameobject.Find() in my GUI text class(not an actual GUI text object but my own custom GUI text class) here's the code for that:
using UnityEngine;
using System.Collections;
public class GUITextScript : MonoBehaviour {
public float posX;
public float posY;
public float sizeX;
public float sizeY;
Vector3 thisposition;
GameWideScript gamescript;
PlayerControl player;
public string content;
// Use this for initialization
void Start () {
gamescript = GameObject.Find ("GameManager").GetComponent();
player = GameObject.Find ("character").GetComponent ();
}
It throws a NullReferenceException when I try to get the gamemanager object. WHat am I doing wrong?
↧