Unity for OculusGo:通过触摸板沿z轴移动对象

时间:2018-11-08 09:51:19

标签: c# unity3d oculus unity3d-editor oculusgo

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

现在,我想使用oculus的触摸板使沿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;
}

然后在指针类中使用它将其附加到ray:

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;
    }

    }

}

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

预先感谢

0 个答案:

没有答案