Hi all, I’ve been trying every solution I can find for this but not sure whats going on.
I have a script attached to a chest collider trigger that detects the person entering the collider. That script should access my GUI script and change a boolean variable (chestGUI) from false to true.
+++ Chest Collider Script +++
//External Access
var playerGUI : MainGUI;
playerGUI = GetComponent(MainGUI);
function OnTriggerEnter(other : Collider)
{
if(this.gameObject.name == "ChestTrigger") // if the object this script is attached to is a chest trigger
{
// If external MainGUI variable is false (Throwing null reference exception)
if(playerGUI.chestGUI == false)
{
// Change it to true
playerGUI.chestGUI = true;
}
}
}
+++ MainGUI Script +++
var chestGUI : boolean = false;
function OnGUI () {
if(chestGUI)
{
GUI.Box (Rect (80,80,70,50), "Chest contents listed here");
}
}
+++ Error +++
NullReferenceException: Object reference not set to an instance of an object objTrigger.OnTriggerEnter (UnityEngine.Collider other) (at Assets/Scripts/Collisions/objTrigger.js:12)
I appreciate anyone’s help. Thanks.