Accessing Information Between Scenes in Unity

I have a class in Unity that contains a list of toggle switches that turn on and off in a separate scene from the rest of my game. I want the user to select one button and then perform the corresponding action in my main game when they return to this scene. However, I had a problem sending information between scenes.

Currently, my toggle class is as follows:

private bool action1 = false;
public bool Action1
{
    get { return action1;}
}

void OnGUI() 
{
    action1 = GUI.Toggle(new Rect(10, 10, 100, 30), action1, "test");   
}

void Update()
{
    if(Input.GetButton("Jump"))
    {
        Application.LoadLevel("Main");
    }
}

Then in the class contained in my main scene, I have the following code:

private ActionClass actionIsOn = new ActionClass();
void Start() 
{
    if(actionIsOn.Action1 == true)
    {
        Debug.Log("action is on");
    }
    else
    {
        Debug.Log("nothing happening");
    }
}

However, when I check this, nothing happens.

Have I configured this correctly? Is there a better way to transfer this information from one scene to another?

+4
source share
1

№1:

, .

public static class GlobalData
{
       public static bool SomeBooleanFlag;
}

, GlobalData.SomeBooleanFlag - , .

№ 2:

Object.DontDestroyOnLoad, , . , , ( ), , .

http://docs.unity3d.com/Documentation/ScriptReference/Object.DontDestroyOnLoad.html

+7

All Articles