When my game loads I have an empty scene.
When i press options on ps4 pad my player character and 1st enemy appear. This worked fine.
I wanted to add in that some HUD text also appears when ‘options’ is pressed. So I set up a canvas, some UI text and set it to load at the same time.
At runtime when I hit options I am getting an object reference not set error, even though it is actually working and the text is appearing.
where am I going wrong?
using UnityEngine;
using UnityEngine.UI;
public class GameController : MonoBehaviour {
private bool gameStarted = false;
public Text text;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void FixedUpdate () {
if (Input.GetButton ("PS4_Options") && gameStarted == false)
{
gameStarted = true;
text.enabled = true;
PlayerReady ();
}
}
void PlayerReady(){
GameObject player1 = Resources.Load ("Player") as GameObject;
GameObject enemy = Resources.Load ("Sci-Fi_Soldier") as GameObject;
Instantiate (player1);
Instantiate (enemy);
}
}