I am trying to call a function from another scrip without using GameObject.Find() to make the project more efficient. this is the function i am trying to run.
public class DoorEventHandler : MonoBehaviour {
public static DoorEventHandler doorEventhandler;
public delegate void GeneralEventHandler();
public event GeneralEventHandler toggleState;
public void CallEventToggleState()
{
if(toggleState != null)
{
toggleState();
}
}
}
The function itself does work as I can call it if I use GameObejct.Find()
I tried to call the function like this:
DoorEventHandler.doorEventhandler.CallButtonPressedEvent();
However, doing this gives me a “NullReferenceException: Object reference not set to an instance of an object”. I am not sure why this is happening as both of the scripts are in the same name spaces and are both attached to objects.
Thanks in advance for answers.
Tried doing as you suggested to no avail. I have been trying to figure this one out for quite a while and that reference to the pickup is probably debris from my desperate attempts to solve this :P
– Droki