- Home /
How do i change script in one scene without changing it in all the scenes
i have 2 scenes in scene one i want to show a short dialogue and when there are no more scentences left i want it to load the next scene. but in scene 2 if there are no more sentences left i dont want it to load a new scene but just continue with the game. so how do i write the script so that it works different in both scenes?? becouse they will have the same names for classes and stuff.
Answer by Favouriteless · Jun 13, 2019 at 11:31 AM
The best way to do this would be to have 2 seperate scripts.
If you really want to use one script, you can use SceneManager.GetActiveScene() to find which scene is active and have 2 functions for the dialogue. For example
print("line1")
print("line2")
if(SceneManager.GetActiveScene == 1):
LoadScene()
else if(SceneManager.GetActiveScene == 2):
ContinueScene()
oke Thanx! but if i have 2 seperate scripts with the same names for variables will that effect the other script? or can i just have the same names in different scripts without a problem?
This is an extremely late reply as I never got a notification but no, it will not affect it. The variable names are just references to memory addresses, the computer is using the memory address, not the variable name.
Sorry but separate scripts is definitely not the best way to do this. If the objects share a lot of functionality, they should share code. You can create variations in behaviour in many ways, all of which are far better than what's in this answer.
And the alternative solution is even worse as it locks things to scene indices. Why would you do that when you can just have a public flag that chooses between the Load and Continue options?
Your answer
![](https://koobas.hobune.stream/wayback/20220612203128im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Spawn A prefab after death 3 Answers
How to reduce my script ? 0 Answers
Trying to find the highest number than add it to itself. 2 Answers
How would i make it transform player.position =target.position? 2 Answers
Point Counter Works Only Once! 1 Answer