unityについて質問です
実現したいこと
おはよう、とインプットフィールド内にうったら、あるオブジェクトが表示されて、二秒後に違うオブジェクトがまた表示される。おはようという言葉以外だったら、インプットフィールド内の文字は消える。というものを作りたい
困っていること
下記のコードで実践してみたところ、おはよう以外の言葉であればインプットフィールド内から消えるが、おはようと打つと、インプットフィールド内におはようがもう一つ現れ、おはようおはようの文字が消えるという現象が起こっている。
c# コード
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class camera : MonoBehaviour
{
public InputField inputField; public GameObject hello; public GameObject helloworld; public GameObject birdFalse; public GameObject what; public GameObject come; string text; bool rightText; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { } public void PushSendButton() { text = inputField.text; switch (text) { case "おはよう": { rightText = true; } break; } if (rightText == true) { hello.SetActive(true); Invoke("helloworldMessod", 2); } else { resettext(); } } void resettext() { inputField.text = ""; } void helloworldMessod() { helloworld.SetActive(true); }
}