1

我编写了一个脚本,通过从控制器投射的光线来选择一个带有刚体组件的对象并移动它。我制作对象,控制器的子对象,然后在场景中移动它。我已经有一个脚本,可以通过从控制器投射的光线检测对象,将其拾起并使用控制器上下左右移动。

现在,我想使用 oculus go 的触摸板沿 z 轴制作选定的对象。但是我不知道该怎么做。这是我用来附加到父级的功能:

 public virtual void Store(Transform NewParent)
{
    //The following stops the object being effected by physics while it's in 
the players hand
    rb.isKinematic = true;
    //And fixes it to the new parent it is given by the player script to 
follow.
    transform.parent = NewParent;
    //It then resets it's position and rotation to match it's new parent 
object
    //transform.localRotation = Quaternion.identity;
    //transform.localPosition = Vector3.zero;
}

然后我在指针类中使用它来将它附加到射线上:

void Intract()
{
    //We set up the input "OculusPrimaryIndexTrigger" in the Input manager
    if (OVRInput.GetDown(OVRInput.Button.PrimaryIndexTrigger))
    {
        selectVisual.ClearObject();
        //Check if you are holding something you can throw first
        if (inHand != null)
        {
            inHand.Release(controllerRef.forward, throwForce);
            inHand = null;
            //We do this check here to prevent Errors if you have nothing 
selected
        }
        else if (selectedObject != null)
        {
            //Check if you can pick up the selected object second
            if (selectedObject.GetComponent<PickUp>())
            {
                //Beacuse PickUp is a child of PropBase, we can ask InHand 
to store selectedObject as PickUp, rather than use GetComponent
                inHand = selectedObject as PickUp;
                inHand.Store(holdingRef);
                //If non of the above were valid then simple call the 
trigger function of the selected object
            }
            else
            {
                selectedObject.Trigger();
            }
        }
        //If you have a object that you need to hold down a button to 
intract with
    }

    else if (pointerOver != null)
    {
        if (pointerOver.GetComponent<PropBase>())
        {
            selectedObject = pointerOver.GetComponent<PropBase>();
        }
        else
        {
            selectedObject = null;
        }
    }
    else
    {
        selectedObject = null;
    }

    }

}

如果有人能指出我正确的方向或帮助我,我将不胜感激!

提前致谢

4

0 回答 0