Hi, in my scene Im trying to load different levels on GUI depending on wether or not an object has been picked up.
Here’s my script:
public class Guibutton4 : MonoBehaviour {
public Texture btnTexture;
public GameObject Inventory;
private AsylInventory asylInventory;
void awake(){
Inventory = GameObject.FindGameObjectWithTag ("Inventory");
asylInventory = Inventory.GetComponent<AsylInventory>();
}
void OnGUI() {
if (GUI.Button(new Rect(20, 10, 200, 30), "Return to cell")){
if (asylInventory.GetComponent<AsylInventory>()){
asylInventory.hasPick = true;
Application.LoadLevel("AsylumCell1");
}
if (asylInventory.GetComponent<AsylInventory>()){
asylInventory.hasPick = false;
Application.LoadLevel("AsylumCell M");
}
}
}
}
I have an empty game object with an inventory script called “AsylInventory” with a bool that becomes true when the object is picked up.
I want the level called “AsylumCell1” to load on GUI when the “has Pick” bool is true in the “AsylInventory” script and the level “AsylumCell M” to load on GUI when the “has Pick” bool is false in the “AsylInventory” script.
Simple right?
But with this script I keep getting the error “Object Reference not set to an instance of an object” and when I double click the error it highlights this line: “if (asylInventory.GetComponent()){”
I can’t figure out why, can anyone help me please?