void Update()
    {
        // If fingers are within hovering distance of the object
        if (intObj.isPrimaryHovered)
        {
            currDistance = intObj.primaryHoverDistance;
            // If your fingers are within the objects proximity and the button isn't already being held down
            if (intObj.primaryHoverDistance < proximityDistance && state == null)
            {
                state = "Active";

                // Call Button Pressed Function
                buttonPress bPScr = gameObject.GetComponent <buttonPress>();
                bPScr.ButtonPressed();
            }
            // If fingers have left the objects proximity
            else if (state == "Active" && intObj.primaryHoverDistance > proximityDistance)
            {
                state = null;

                // Call Button UnPressed Function
                buttonPress bPScr = gameObject.GetComponent <buttonPress>();
                bPScr.ButtonUnPressed();
            }
        }
    }
Beispiel #2
0
    void OnTriggerExit(Collider collider)
    {
        //Detect fingers not touching the object anymore
        if (isHands == true)
        {
            //If object was active
            if (state == "Active")
            {
                for (int i = 0; i < collidingObjects.Length; i++)
                {
                    // If colliding object is the sane trigger object
                    if (collider.gameObject.GetInstanceID() == collidingObjects [i].GetInstanceID())
                    {
                        state      = null;
                        isTouching = false;

                        if (gameObject.name == "2DButton")
                        {
                            // Call Button UnPressed Function
                            buttonPress bPScr = gameObject.GetComponent <buttonPress> ();
                            bPScr.ButtonUnPressed();
                        }                        //PLACE ELSE IF CONDITION(S) HERE TO ADD MORE FEATURES FOR DIFFERENT TYPES OF BUTTONS
                    }
                }
            }
        }
    }