コード例 #1
0
    // Update is called once per frame
    void FixedUpdate()
    {
        Vector3 movement = new Vector3();
        float   rot      = 0.0f;

        if (VRBehaviour)
        {
            if (interact.AttachedHands.Count == 2)
            {
                this.Active = true;
                this.transform.SetParent(player.transform);

                // Déplacement du drone sur le plan (X, Z)
                Vector2 leftAxis = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick);
                movement.x = leftAxis.x;
                movement.z = leftAxis.y;

                // Montee, descente du drone
                float trigger = OVRInput.Get(OVRInput.RawAxis1D.LIndexTrigger);
                if (trigger > 0.0)
                {
                    movement.y = 50f * -trigger;
                }
                else
                {
                    trigger = OVRInput.Get(OVRInput.RawAxis1D.RIndexTrigger);
                    if (trigger > 0.0)
                    {
                        movement.y = 50f * trigger;
                    }
                    else
                    {
                        movement.y = 0f;
                    }
                }

                // rotation
                Vector2 rightAxis = OVRInput.Get(OVRInput.Axis2D.SecondaryThumbstick);
                rot = rightAxis.x;

                debug.text = "direction : " + movement + "\n" +
                             " Drone pos : " + this.DroneControlled.transform.position + " | Drone Rot : " + this.DroneControlled.transform.rotation;
            }
            else if (interact.AttachedHands.Count == 1)
            {
                this.Active = false;
                this.transform.SetParent(player.transform);
                this.GetComponent <Rigidbody>().useGravity = true;
            }
            else
            {
                this.Active           = false;
                this.transform.parent = null;

                if (OVRInput.Get(OVRInput.Button.One))
                {
                    this.ResetController();
                }
            }
        }
        else
        {
            float moveUp; // Input monter / descendre
            if (Input.GetKey(KeyCode.Space))
            {
                moveUp = 50.0f * DroneControlled.Speed;
            }
            else if (Input.GetKey(KeyCode.C))
            {
                moveUp = -50.0f * DroneControlled.Speed;
            }
            else
            {
                moveUp = 0.0f;
            }

            movement = new Vector3(Input.GetAxis("Horizontal"), moveUp, Input.GetAxis("Vertical"));

            if (Input.GetKey(KeyCode.Q))
            {
                rot = -2.0f;
            }
            else if (Input.GetKey(KeyCode.E))
            {
                rot = 2.0f;
            }
            else
            {
                rot = 0.0f;
            }
        }

        DroneControlled.ApplyForces(movement, rot);
    }