Help with loading new levels - restarting scripts

I have created the start and first level of a game. I would like to add several more levels to the game but need some help. The game is a simple shooter game that I should be able to reuse almost all the scripts in the subsequent levels but I need then to reset. Is this possible and if so how do I do such a thing. Also is it possible to set the var in the scripts different for each level without using a copy of the script. Please let me know what I need to post if you do not understand the question.

Thanks

Monte

The scripts resets when you change to another scene , what’s your problem?

the script will reset if you’re loading them into another scene, unless you are using doNotDestroyOnLoad().

On your second point. If you declare the variables you want to change outside of your Update() function (usually at the very top of the script),they will appear in the inspector for the object they are attached to. Then you can change the variable values in the inspector and it will only affect that particular game object.

so your script would look like this

var levelNumber : int;
var health      : int;
var numberEnemies : int;

function Update()
{
   //your update scripts here
}

Then in the inspector you will have some options in the script component called

Level Number

Health

Number Of Enemies

you can reuse the same script in each level setting these variables throught the inspector (you can set the values of the variables in the script but the inspector version overwrites whatever is in the actual script when you run the game)

I hope this makes some sort of sense, and helps you out

Put the script on different prefab and use one prefab per scene.

Or create a unique prefab, add an instance of this prefab in each scene and override their value in the Inspector like @chrisallen suggested.

One way or the other, you don’t need to copy/paste your script.

Thanks for the help guys. I think I understand. I made an exact copy of level one by duplicating it and when I loaded level two all it loaded as if all ready played. In other words exactly like level one finished. I hope that makes sense. So if the scripts reset why would that happen?