0
私はダイアログポップアップを作ろうとしていて、同じボタンを使ってNPCとやりとりして、プレイヤーが読み終わったらメニューを消したいと思っています。現在、テキストパネルが表示され、瞬時に消えます。コードは次のとおりです。Unity3D - Input.GetButtonDown()が私のコードで2回発射されるのはなぜですか?
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class NPC : MonoBehaviour {
public GameObject TextPanel;
private bool isInteractable = false;
void Update()
{
if (Input.GetButtonDown("Accept") && isInteractable)
{
NPCInteraction();
Debug.Log("Button Press 1");
}
}
void OnTriggerStay()
{
isInteractable = true;
}
void OnTriggerExit()
{
isInteractable = false;
}
void NPCInteraction()
{
TextPanel.GetComponentInChildren<Text>().text = "This is the dialog from this NPC";
TextPanel.SetActive(true);
if (Input.GetButtonDown("Accept"))
{
TextPanel.SetActive(false);
Debug.Log("Button Press 2");
}
}
}
「承認」ボタンを1回押すと、ログには両方のボタンが押されて表示されます。一度登録するように入力を修正するにはどうすればよいですか?