【发布时间】:2019-11-26 15:19:37
【问题描述】:
下午好!
我正在尝试制作一个需要虚拟按钮来回答的简单 AR 问答游戏。如果按下正确的按钮,游戏就会继续。
问题是:如何在按下虚拟按钮时停用所有虚拟按钮? 我已经查看了几乎所有关于此的主题,但无法弄清楚如何使这项工作。 此时我可以按所有按钮,但只能按一次。
提前致谢(抱歉我的英语不好)!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Vuforia;
public class PushToDebug : MonoBehaviour, IVirtualButtonEventHandler
{
public string vbName;
public AudioSource audi;
void Start()
{
//Register with the virtual buttons TrackableBehaviour
VirtualButtonBehaviour[] vrb = GetComponentsInChildren<VirtualButtonBehaviour>();
audi = GetComponent<AudioSource>();
for (int i = 0; i < vrb.Length; i++)
vrb[i].RegisterEventHandler(this);
}
public void OnButtonPressed(VirtualButtonBehaviour vb)
{
vbName = vb.VirtualButtonName;
if (vbName == "VB1")
{
Debug.Log("Button 1 is pressed!");
audi.Play();
vb.GetComponent<VirtualButtonBehaviour>().enabled = false;
}
else if (vbName == "VB2")
{
Debug.Log("Button 2 is pressed!");
audi.Play();
vb.GetComponent<VirtualButtonBehaviour>().enabled = false;
}
else
{
Debug.Log("Button 3 is pressed!");
audi.Play();
vb.GetComponent<VirtualButtonBehaviour>().enabled = false;
}
}
public void OnButtonReleased(VirtualButtonBehaviour vb)
{
if (vbName == "VB1")
{
Debug.Log("Button 1 is released!");
}
else if (vbName == "VB2")
{
Debug.Log("Button 2 is released!");
}
else
{
Debug.Log("Button 3 is released!");
}
}
}
感谢您的回复! 由于某些奇怪的原因,它不仅可以正常工作。
我添加了Debug.Log("DeactivateButtons is called!");,这个方法根本没有被调用。
【问题讨论】: