- Home /
Question by
Mr-Asad955 · Mar 31, 2015 at 10:23 AM ·
buttondetectionloadlevelload scenecontinue
How to detect from which button the scene is loaded?
for example if we have: void OnMouseDown(){ if(this.name == "continue"){ LoadLevel("level2"); }
if(this.name == "continue-prev-game"){ LoadLevel("level2");
} }
Now here are two buttons, continue and continue-prev-button. i want to know how can i detect (when i reach level 2), from which button i reached at Level 2. continue or continue-prev-game.
Comment
Answer by Owen-Reynolds · Mar 31, 2015 at 04:21 PM
Use a dontDestroyOnLoad to "carry" data between scenes (lots of info on how to make one. They are a bit tricky.) Could also probably use a static variable.
Suppose you call it sceneData. button1 can set sceneData.buttonPressed=1;
before running LoadLevel(2). In the main Start() or Awake) of level 2, read sceneData.buttonPressed
and do what it says.
Your answer
![](https://koobas.hobune.stream/wayback/20220613191742im_/https://answers.unity.com/themes/thub/images/avi.jpg)