- Home /
Change scene and play it by clicking UI Button? Scene does just load but not start playmode?
I have two games and I would like to have one GUI with two buttons: Button 1 to load and start game 1 and Button 2 to load and start game 2. This works with one game1 but as soon as I press Button 2 the scene is just loaded but it does not start play mode. Why? How can I change this so that it works?
Here my code:
public void StartGameFeedback () {
startingGame = true;
}
public void StartGameFeedforward() {
startingGameFeedfoward = true;
}
public void startScene() {
if(startingGame)
Application.LoadLevel("WireGame2D_V6");
else if (startingGameFeedfoward)
Application.LoadLevel("FeedForwardGame_V4");
}
All my 3 scenes are in the build settings. Both buttons do have the function on it to load the scene. But as I said for game 2 the scene is just loaded but I like that it starts also playing.
Thank you for your help!
Answer by fugogugo · Apr 03, 2016 at 10:11 PM
uuuhm... my guess is that you forgot to set all the flag to false after each load level. and also with that condition, if startingGame is true, FeedFowardGame_V4 won't be called whatever the startingGameFeedForward value is, that's because it's the conditional result of your code
but again. why did you use flag just to load level? can you just do it like this?
public void StartGameFeedback () {
Application.LoadLevel("FeedForwardGame_V4");
}
public void StartGameFeedforward() {
Application.LoadLevel("WireGame2D_V6");
}
it's much more straightforward and less headache.
Your answer
Follow this Question
Related Questions
Unity 5: UI button OnPointerDown not function as expected 1 Answer
I can't click to an UI button. 3 Answers
I made an resume button, but I don't know how to code it to close my pause menu, any tips? 2 Answers
I need to move a sprite when an UI button is clicked 1 Answer
[5.4 - Unity2D - Android] UI Button Requires Child Text? 0 Answers