Hey guys,
I’m fairly new to Unity and scripting, I basically want to be able to change to the next scene by the user typing in the correct answer to a question in an input-field.
Any help would be appreciated!
Thanks,
Z
Hey guys,
I’m fairly new to Unity and scripting, I basically want to be able to change to the next scene by the user typing in the correct answer to a question in an input-field.
Any help would be appreciated!
Thanks,
Z
Create this script and attach it to something in your scene:
using UnityEngine;
using UnityEngine.SceneManagement;
public class AnswerChecker : MonoBehaviour {
public void CheckTheAnswer(string input) {
if(input == "The Right Answer") SceneManager.LoadScene("TheNextScene");
}
}
Then on your input field in the inspector, go to the On End Edit section, click the plus sign, then drag the object you attached that new script to into the box, then select “CheckTheAnswer” from the dropdown.
You’ll need to change “The Right Answer” and “TheNextScene” to whatever the actual answer and scene name are.
Thank you so much, you are a life saver. It worked perfectly.
I tried to use this code but not work.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class prueba_pass2 : MonoBehaviour
{
public void Password(string input)
{
if (input == "benito") SceneManager.LoadScene("realidad_aumentada");
else
Debug.Log("Wrong Password");
}
}
When i type benito into the inputfield the console always type Wrong Password, why?