public GameObject modelA;
public GameObject modelB;
void Update()
{
OVRInput.Update();
if (OVRInput.Get(OVRInput.Button.One))
{
//Hide model A
modelA.SetActive(false);
//Show model B
modelB.SetActive(true);
}
}
如果你不想激活/取消激活游戏对象,只需启用/禁用MeshRenderer组件:
public GameObject modelA;
public GameObject modelB;
void Update()
{
OVRInput.Update();
if (OVRInput.Get(OVRInput.Button.One))
{
//Hide model A
modelA.GetComponent<MeshRenderer>().enabled = false;
//Show model B
modelB.GetComponent<MeshRenderer>().enabled = true;
}
}
List<InputDevice> devices = new List<InputDevice>();
InputDevices.GetDevicesWithCharacteristics(InputDeviceCharacteristics.Controller |
InputDeviceCharacteristics.TrackedDevice | InputDeviceCharacteristics.Right,
devices);
foreach (var item in devices)
{
List<InputFeatureUsage> l = new List<InputFeatureUsage>();
item.TryGetFeatureUsages(l);
bool resBool;
foreach (var i in l)
{
// I guess there could be a more elegant solution here.
if (i.name == "TriggerButton")
{
item.TryGetFeatureValue(i.As<bool>(), out resBool);
if (resBool) {
modelA.GetComponent<Renderer>().enabled = true;
modelB.GetComponent<Renderer>().enabled = false;
} else {
modelA.GetComponent<Renderer>().enabled = false;
modelB.GetComponent<Renderer>().enabled = true;
}
}
}
}
2条答案
按热度按时间hgc7kmma1#
要隐藏游戏对象,使用
SetActive
函数并传递true/false来显示/隐藏它。is激活和取消激活游戏对象:如果你不想激活/取消激活游戏对象,只需启用/禁用MeshRenderer组件:
jchrr9hc2#
如果你不想使用Oculus特定的依赖项(如
OVR
),你可以使用UnityEngine.XR.InputDevice
,它应该是通用的