我试图让用户在输入字段中输入一个句子,然后我需要检查用户是否输入了正确的句子,如果他们输入正确,我希望能够改变场景(我使用了Debug.Log作为占位符)。
下面是我的代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class CheckInput : MonoBehaviour {
public InputField WordInput;
// Use this for initialization
void Start () {
}
// Update is called once per frame
public void CheckforWords () {
if (WordInput.text == "please")
{
Debug.Log("Youre a Lad");
}
else
{
Debug.Log ("Nope");
}
}
}
发布于 2017-04-07 08:21:52
要在Unity3D中以编程方式加载级别:
Application.LoadLevel (Destination);
你需要确保你的场景被添加到关卡集合中,否则你会遇到一个空引用。
参考: https://docs.unity3d.com/560/Documentation/ScriptReference/index.html
发布于 2017-04-07 09:54:04
我找到了Inputfield的两个事件: onEndEdit和onValueChange
https://docs.unity3d.com/ScriptReference/UI.InputField-onEndEdit.html https://docs.unity3d.com/ScriptReference/UI.InputField-onValueChange.html
您可以在检查器中进行编辑并使用SceneManager.LoadScene
https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.LoadScene.html
https://stackoverflow.com/questions/43266834
复制相似问题