Accessing a Certain Script

Hello,

I am trying to create a “Back” button for my in-game login menu. The way it works so far is this: Menu > “Login” or “Update”

If you clicked “Login”, it will do “Instantiate(LoginPrefab)”; if you clicked “Update”, it will do “Instantiate(UpdatePrefab)”. Simple.

I need a back button for both instantiated prefabs that will destroy the current instantiated prefab and then send the message “ActivateMenu, true” to a script called “crMenuScript.js” that is in the “Menu” prefab, the one where my menu runs from. ActivateMenu lets me use the menu again.

I’ve done multiple tests, but I can only destroy the instantiated prefab. I always get a “NullReferenceException” when trying to access “crMenuScript” from another prefab.

Forgive me for the newbish post, but I have tried everything I could do and find over the past couple weeks. All of Unity’s scripting reference pages could not help me (perhaps I was using the scripts the wrong way).

Thank you very much,

TheCyberMan

P.S. I would prefer this to be in Javascript, but I just need guidance on getting this to work. I could translate the language to Javascript later if need be.

Rather than do prefabs with different GUI stuff…

do something simliar:

var showMain = true;
var showLevels = false;
var showOptions = false;
var showExitSplash = false;


function OnGUI()
{
    if(showMain)
    //Show main GUI crap.
    //If (Button here for levels, if clicked do this down here.)
    //showMain = false; showLevels = true;
    if(showLevels)
    //Show level selection
    //If (Button here for back to main, if clicked do this down here.)
    //showMain = true; showLevels = false;
    if(showOptions)
    //Show options stuff
    //If (Button here for back to main, if clicked do this down here.)
    //showMain = true; showOptions = false;
    if(showExitSplash)
    //Do splash screen then exit
}

That’s how I do mine… Think of OnGUI as Update() so that it runs every frame, so if something is false, it won’t do under that, if it’s true it will. So then you can disable parts of your GUI, being kind of like layers.

=)