I have been trying to figure this out all day.
My goal is to instantiate a GUIText prefab. I am trying to make all of my scripts use private calls for GameObjects instead of having to drag them into the inspector in Unity. The problem is though, it seems that I lose my clone reference as soon i leave the Start().
To be more specific, I am trying to call a GUIText called “Pause Text” and have the text show up on the screen when I pause my game. The way I have it now apparently works. I have Debug.Logs saying what the GUIText.text is and it alternates between “” and “PAUSED”. BUT, It doesn’t show up at all in the camera view.
Here is my code, hopefully somebody can make heads of what I want. Thanks in advance!
private GameObject createObject;
private GUIText pauseText;
private bool paused = false;
void Start() {
createObject = Resources.Load("Pause Text") as GameObject;
pauseText = createObject.guiText;
pauseText.text = "";
}
void Update () {
if (Input.GetKeyDown(KeyCode.KeypadEnter))
{
paused = !paused;
if (paused == true)
{
pauseText.text = "PAUSED";
Time.timeScale = 0;
}
else if (paused == false)
{
pauseText.text = "";
Time.timeScale = 1;
}
}
}
I tried instantiated the GUIText object, but that always gave null references, and it didn’t seem to work in the first place.
Thanks!