4 scripts in 4 scenes

Hi,

have a menu with 4 points/buttons.
Up to now, I’ve made a main-script for elements, which doesn’t change anymore and 4 scripts in 4 different scenes.
Up to now I’ve got it like this

if button(blabla) {
Application.LoadLevel(“next”);
}

Can I reduce it to only one scene when I click a new menu-point by changing only the relevant script (deactivate the current, load the clicked) and what way would it look like?

Thx

Hy,

yes, you can. In level 0, put your script and give another script to your game object

function Awake()
{
	DontDestroyOnLoad (this);
}

Wonderfull !

Hmm, as far as I know, this command is for saving objects in the scene for the next level.

What I want to realize is to “replace” the script, when another menu-button was clicked.
4 menu-buttons - 4 scipts - and up to now 4 scenes

For that, the dontdestroy-command isn’t right, isn’t it?

Anybody?

Your question isn’t very clear. You want to know how to switch scripts?

// Get current script
var current :MyScript = GetComponent(MyScript);
// Disable
current.enabled = false;
// or destroy
Destroy(current);
// Add new script
var new :MyOtherScript = gameObject.AddComponent(MyOtherScript);

Yes right.

I’ve got 4 scripts in 4 various scenes.
Want to have only one scene with all 4 scripts.
When the app is started the first script is loaded.
When the user is clicking on another menu-point the current script should be disabled and the clicked one should be loaded…

if your talking about having 4 different menues and you want to disable one and hide it away while your using any other… Then you may want to write your script with states in it.

state = 1;
function OnGUI(){
   if (state == 1){
     .. menu 1 stuff;
   }
   if (state == 2){
     .. menu 2 stuff;
   }
}

Does this help?
[/code]

Ahm, no. Wanted to have still 4 scripts.
Your solution would meaning, that I’ve got only one script.
But in 3 of them, I have to fill different arrays with different textures and pics.

Can’t you just enable and disable the scripts cleverly?
At least that the solution i understand for your problem.

So you put all 4 scripts in the same scene. And start by disabling them all and then only enable the one you want running?

You might have to make a enabler manager kinda script or you can use FindObjectOfType i think to find the scripts and enable disable them when something is clicked.

You might want to have a look in the API for OnEnabled and OnDisabled aswell.

Thx Marc

Is this also possible to control by a “main-script”?
Say the main-script “controls” the other scripts laying on the object.
The script reference isn’t this meaningful as I would need it… :wink:
How should I implement it if it would run this way?