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 :slight_smile:

Kinda confused now...

3 Answers

3

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!";
	}
}

}

what is the 0 for?

This is all you need : void Update() { transform.Translate (Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0, Space.Self); } then you go in Menu/Edit/Project Settings/Input, and you set it all up there.

@KristianGrytdal

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.

It seems to me that you're making it a lot more complicated than it is. Input class allows you to map keys and joystick axes to input "labels". So your game can be easily configured for any keyboard layouts. Then Translate can take a Vector3, or three float values. If you want a walking character, Unity has a builtin system with everything you need, jump capabilities and all. It's called the CharacterController, and is found in one of the Standard Packages.

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.

Thank you so much, It worked perfectly! :)