In my game level, i have a few gameobjects that have some children on it.
Once the player interacted with it some stuff happens, like light color changes and such.
Now in the menu, i want to make a “restart” button. At first i tried making it just reboot the whole level
Application.LoadLevel("00_Main");
but i want to cut down the loading time.
its just a few gameobjects i want to reset with the scripts that are attached to it also resetted.
is there some way to do this trought tag or something?
reset everything with tag “ResetMe” in some way?
thank in advance
I would suggest creating a generic reset script something like
public class ResetObject : MonoBehaviour{
public abstract void Reset();
}
then extend this per object for example:
public class BoxResetObject : ResetObject{
public override void Reset(){
//reset parameters here
}
}
Then have a reset manager class that contains an array of all the reset scripts in the scene and a function that you can call when you want to reset the scene such as:
public class ResetManager: MonoBehaviour{
public Reset[] _ResetScripts
public static ResetScene(){
foreach(Reset r in _ResetScripts){
r.Reset();
}
}
}
so if i understand correct, you put this script to each object i want to have reset, and once the “master button” is pressed, it finds al the scripts and resets them ?
Yeah, so you have the generic reset script which you extend per object, so if for example you have a light you want to reset then you would create a new script called LightResetScript which would extend from the generic Reset script and you would attach this script to the light you want to reset and add it to the array on the manager script that is placed in the scene. Then when you want to reset the scene call ResetManager.ResetScene(), from where the condition to reset is met, and the light will be reset to how you want it. Sorry if I haven’t explained it very well.
1 Like