- Home /
Change Scene by answering right
I'm making a guess the movie game, and I need to change to scene "level 1" when the person answers correctly. But now it only says that they answered correctly, Can anybody help my with making the C# script that makes it change scene when the player answers correctly? thanks in advance :)
using UnityEngine; using System.Collections; using UnityEngine.UI;
public class Spawn: $$anonymous$$onoBehaviour {
private string gameName;
private int countGuess;
[SerializeField]
private InputField input;
[SerializeField]
private Text text;
void Awake(){
gameName = "spawn";
text.text = "Guess The Name Of The Game";
}
public void GetInput(string guess){
CompareGuesses(guess);
input.text = "";
}
public void ChangeToScene (string sceneToChangeTo) {
Application.LoadLevel(sceneToChangeTo);
}
public void CompareGuesses (string guess){
if (guess == gameName) {
text.text = "You Guessed Correctly";
} else if (guess != gameName) {
text.text = "Wrong!";
} else if (guess != gameName) {
text.text = "Wrong!";
}
}
}
Answer by KristianGrytdal · Jul 28, 2016 at 02:55 PM
using UnityEngine; using System.Collections; using UnityEngine.UI;
public class Spawn: MonoBehaviour {
private string gameName;
private int countGuess;
[SerializeField]
private InputField input;
[SerializeField]
private Text text;
void Awake(){
gameName = "spawn";
text.text = "Guess The Name Of The Game";
}
public void GetInput(string guess){
CompareGuesses(guess);
input.text = "";
}
public void ChangeToScene (string sceneToChangeTo) {
Application.LoadLevel(sceneToChangeTo);
}
public void CompareGuesses (string guess){
if (guess == gameName) {
text.text = "You Guessed Correctly";
} else if (guess != gameName) {
text.text = "Wrong!";
} else if (guess != gameName) {
text.text = "Wrong!";
}
}
}
Answer by NinjaLlama · Jul 28, 2016 at 02:55 PM
firstly do you have the statement using UnityEngine.SceneManagement at the top? otherwise, have you added the scene that it should switch to in the build settings? Hope this helps.
Answer by DenisTribouillois · Jul 28, 2016 at 03:20 PM
Add the scene you want to load to the build settings : File -> Build Settings... -> Add Open Scenes.
In script, when the player answered correctly use :
SceneManager.LoadScene(sceneName);
And don't forget to add :
using UnityEngine.SceneManagement;
at the beginning of your file.
Application.LoadLevel should work but it's obsolete.
Your answer
Follow this Question
Related Questions
Making an image appear from a different script 0 Answers
Changing something in another scene by answering correctly 1 Answer
Changing something in another scene by answering correctly with GlobalManager 0 Answers
Saving Player Position between scenes? 1 Answer
To pass a variable between scenes should I use scriptableobject or static ? 1 Answer