Passing a variable through the main menu

Hi, actually in my main menu I have one option only, one called "Play", I want now to implement a couple of them "Single player play" and "Two players play". On my main Scene called "TheGame" I have both players, but I want that if I someone clicks on Single Player, the object of my second player disapears. Anyone knows what I have to do? Here I have attached the script of the button "Play" on my Main menu

if (GUI.Button( Rect( (Screen.width/2)-70, Screen.height -160, 140, 70), "Play"))
    isLoading = true;

Hope you can help me, thanks.

You could have a "GameManager" object which holds a variable for the number of players. Just be sure to have this in a script attached to it:

function Awake () {
DontDestroyOnLoad (transform.gameObject);

This way the object won't get destroyed between scenes.

When the player clicks the Single Player button just set the number of players variable to 2. From there when you load the next scene you can check the number of players (probably in your Awake or Start function) and do whatever you need to with destroying/creating players.

the best way to do it is using PlayerPrefs

read the link here

code snippet:


loading it

if(PlayerPrefs.GetInt("player")==1) ....