- Home /
The question is answered, right answer was accepted
Whats the best method to change a script in one scene, without changing the same script in a different scene.
In my game, I have 2 chapters. I want to make chapter 2 harder than chapter 1. Both chapters have the same gameobjects and scripts, and I want to edit the scripts in chapter 2 to make the game harder. Is there a proper way of messing with a script in one scene without affecting the same script in another scene? Would I need to make new Scripts?
Answer by UnityedWeStand · Jul 27, 2020 at 08:31 PM
In general, the only changes that will persist across scenes are any changes made to the script logic itself and any variables that aren't set in the Unity Editor or by other gameobjects in the scene (ex. private variables)
For example, you could define a generic "Enemy" class and have its health, strength, and defense be public variables. In each scene, you can set each instance of the Enemy class to have different health, strength, and defense values as you please. Even though you have only a single base script, each gameobject would operate according to whatever different values of health, strength, and defense you put in.
However, if you want the enemies in different scenes to have different AI or otherwise follow different game logic, then you would need to write two scripts.