Пример #1
0
    // Update is called once per frame
    void Update()
    {
        // If the menu is showing do not do anything
        if (vrManager.menuManager.IsShowing())
        {
            return;
        }

        // Check if the hand is out of sight (the gesture is not being detected)
        if (transform.position == gesture.GetDefaultPosition())
        {
            // Drop the object
            grabbed = null;
        }

        // Check if the timer finished
        if (timer.IsRunning() && timer.IsFinished())
        {
            // The object is grabbed and the timer is stopped (hidden)
            timer.Stop();
            timer.ResetValues();
            grabbed = intersected;
        }

        // Check if it is grabbing an object
        if (grabbed != null)
        {
            // The object is placed to the right of the hand as if it is grabbing it
            // The position is a point perpendicular (Cross Operation) to the vector between the cam and the gesture and the cam's up vector.
            Vector3 cam           = Camera.main.transform.position;
            Vector3 ges           = this.transform.position;
            Vector3 camToGesture  = new Vector3(ges.x - cam.x, ges.y - cam.y, ges.z - cam.z);
            Vector3 perpendicular = Vector3.Cross(camToGesture, Camera.main.transform.up);
            grabbed.transform.position = this.transform.position + (perpendicular.normalized * -0.6f);
        }
    }