Hi everyone! I’m trying to create a quiz game from the tutorial provided by Unity. I finished said tutorial and added many features on my own. Right now, I am trying to create an optional timed mode that becomes available when the player gets a perfect score on the game. So far, I have made a separate TimeLimit script that holds all the code that runs the timed mode. If that script is enabled, timed mode runs smoothly. However, I am trying to make that script (or the GameObject housing it) inactive until the player gets a perfect score. I am trying to accomplish this currently by using the script below, which returns a NullReferenceException:
public void TimedMode()
{
GameObject.Find("TimeLimit").GetComponent<TimeLimit>().enabled = false;
}
I have checked my spelling and tried to deactivate the overarching TimeLimit GameObject (as opposed to the script in it), but neither has changed anything. I also have checked to make sure my GameObject is not null, so that isn’t the problem either. The actual GameObject is in a separate scene from the one this script is in, but everything I’ve seen says GameObject.Find should search all scenes. If anyone has any ideas on how I can fix this problem (or if you need more info), please let me know! Thanks!
P.S. I should probably mention that my ultimate goal will be to start the script deactivated and then reactivate it with this script. Right now I am just trying to do the opposite so I can make sure it works and I understand it.