Search Unity

Passing Variables between Scenes !!

Discussion in 'Scripting' started by gharaibeh, May 26, 2011.

  1. gharaibeh

    gharaibeh

    Joined:
    Apr 26, 2011
    Posts:
    115
    I need to send the start up selection options Scene(0) variables and load it to my game which is Scene(1).
    I used
    GameSelect =GameObject.FindGameObjectWithTag("GameController");
    GameSelection = GameSelect.GetComponent<MainCode>() ;
    DontDestroyOnLoad(transform.gameObject);

    but always i got a error msg : Object reference not set to an instance of an object !!


    :confused::confused::confused::confused::confused:
     
  2. svenskefan

    svenskefan

    Joined:
    Nov 26, 2008
    Posts:
    282
    Hi!
    Which line gives you the error message?
     
  3. gharaibeh

    gharaibeh

    Joined:
    Apr 26, 2011
    Posts:
    115
    inside the function that send variables to next level :

    GameSelection.SetSelection(...data from scene1...);


    Hint: SetSelection() found in the next level
     
  4. rkite

    rkite

    Joined:
    Feb 22, 2010
    Posts:
    33
    I solved this issue by creating a GameObject and giving it a script with all the info i wanted to move to the next scene.

    Make sure you are keeping the right game Object

    DontDestroyOnLoad(this.gameObject); // keeps this GameObject alive after load is called

    If or when you want these to be destroyed you have to call

    Object.Destroy(gameObject);
     
    Last edited: May 26, 2011
  5. gharaibeh

    gharaibeh

    Joined:
    Apr 26, 2011
    Posts:
    115
    I Solved my problem with PlayerPrefs as following :

    PlayerPrefs.SetInt("bye2", selGridInt2);