啊
void FixedUpdate()
{
device = SteamVR_Controller.Input((int)trackObj.index);
if (device.GetTouch(SteamVR_Controller.ButtonMask.Trigger))
{
// 扳机被触碰,一直为true
//Debug.Log("tttttriger");
}
if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Trigger))
{ //一次为true
Debug.Log("triger down");
}
if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Trigger))
{ // 一次为true
Debug.Log("triger up"); }
if (device.GetPress(SteamVR_Controller.ButtonMask.Trigger))
{ // 扳机被按下 一直为true
Debug.Log("press triger");
}
if (device.GetPress(SteamVR_Controller.ButtonMask.Touchpad))
{ // 中间圆型系统面板
Application.LoadLevel(0); Debug.Log("Touchpad Touchpad"); }}
void OnTriggerStay(Collider col) {
// 抓物体
if (device.GetTouch(SteamVR_Controller.ButtonMask.Trigger))
{ col.attachedRigidbody.isKinematic = true;
//物体失去刚体属性
col.transform.SetParent(gameObject.transform); }
if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Trigger))
{ col.attachedRigidbody.isKinematic = false; col.transform.SetParent(null);
// 仍物体
tossObj(col.attachedRigidbody); } }
void tossObj(Rigidbody rigidbody) {
rigidbody.velocity = device.velocity; rigidbody.angularVelocity = device.angularVelocity;
}
// 手柄抓去物体,手柄具有碰撞,首先需要勾选手柄的isTrigger,如果勾选方块的这个选项,那么方块(含有rigidbody属性)就会一直掉下去,然后在手柄上添加处理含有刚体的方块!