コード例 #1
0
ファイル: hand.cs プロジェクト: rodLouzada/VR-Project-2
    private void OnTriggerStay(Collider c)
    {
        Rigidbody rb = c.attachedRigidbody;

        if (rb == null)
        {
            return;
        }

        PickupObject p = rb.GetComponent <PickupObject>();



        if (p == null)
        {
            return;
        }

        float triggerValue;

        if (ct == OVRInput.Controller.LTouch)
        {
            triggerValue = OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger);
        }
        else if (ct == OVRInput.Controller.RTouch)
        {
            triggerValue = OVRInput.Get(OVRInput.Axis1D.SecondaryHandTrigger);
        }
        else
        {
            triggerValue = 0;
        }                         // OVRInput.Get(OVRInput.Axis1D.SecondaryHandTrigger); }

        if (attachment == null && triggerValue > pickTriggerTrashHold)
        {
            attachment = p;

            attachment.pickedUp(this.transform);
            MeshRenderer[] meshHand = GetComponentsInChildren <MeshRenderer>();

            foreach (MeshRenderer m in meshHand)
            {
                m.enabled = false;
            }
        }
        if (attachment != null && ct == OVRInput.Controller.LTouch && OVRInput.GetDown(OVRInput.Button.PrimaryIndexTrigger))
        {
            c.GetComponent <gun>().shoot();
        }
        if (attachment != null && ct == OVRInput.Controller.RTouch && OVRInput.GetDown(OVRInput.Button.SecondaryIndexTrigger))
        {
            c.GetComponent <gun>().shoot();
        }

        if (attachment != null && triggerValue < releaseTriggerTrashHold)
        {
            attachment.released(this.transform, OVRInput.GetLocalControllerVelocity(ct));

            attachment = null;

            MeshRenderer[] meshHand = GetComponentsInChildren <MeshRenderer>();

            foreach (MeshRenderer m in meshHand)
            {
                m.enabled = true;
            }
        }



        if (attachment != null && c.gameObject.CompareTag("rst") && triggerValue > pickTriggerTrashHold)
        {
            Scene scene = SceneManager.GetActiveScene();
            SceneManager.LoadScene(scene.name);
        }
    }