Unity3d - Vuforia-Unity: How to enable or disable a virtual button?

﹥>﹥吖頭↗ 提交于 2019-12-13 02:57:51

问题


Unity3d - Vuforia-Unity: How to enable or disable a virtual button?


回答1:


Guess I found the solution myself!!

For Unity and Vuforia:

Approach #1:

As every entity in Unity is a GameObject, we can find virtual button using approach below:

To enable/disable a virtual button in C# script:

var myVirtualBtn = GameObject.Find("myVirtualButtonName"); // gameobject name above transform settings section
if(myVirtualBtn != null){
    myVirtualBtn.GetComponent<VirtualButtonBehavior>().enabled = true; // Makes touchable virtual btn.
    myVirtualBtn.GetComponent<VirtualButtonBehavior>().enabled = false; // Makes untouchable virtual btn.
}

Approach #2:

Skip registration of event handler associated with your virtual button

VirtualButtonBehaviour[] vbs = GetComponentsInChildren<VirtualButtonBehaviour>();
    for( int i = 0; i< vbs.Length; ++i)
    {
       if(vbs[i].VirtualButtonName != "myVirtualButtonName") // Skip registration
            vbs[i].RegisterEventHandler(this);
    }


来源:https://stackoverflow.com/questions/51323819/unity3d-vuforia-unity-how-to-enable-or-disable-a-virtual-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!