Quantcast
Channel: Questions in topic: "dontdestroyonload"
Viewing all articles
Browse latest Browse all 416

How to access a game object that wasn't destroyed on load?

$
0
0
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?

Viewing all articles
Browse latest Browse all 416

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>