示例#1
0
    // Update is called once per frame
    void Update()
    {
        float dist = distance;


        Ray        raycast = new Ray(transform.position, transform.forward);
        RaycastHit hit;
        bool       bHit = Physics.Raycast(raycast, out hit);

        if (bHit && hit.distance < distance)
        {
            dist = hit.distance;

            if (prevGO != null && prevGO != hit.transform.gameObject)
            {
                if (prevGO.GetComponent <PointableObject>() != null)
                {
                    prevGO.GetComponent <PointableObject>().PointerExit();
                }
            }

            currContact = hit.transform.gameObject.GetComponent <PointableObject>();
            if (currContact != null)
            {
                isActive = true;
                SetPointerColor(isActive);
                currContact.PointerEnter();
            }

            prevGO = hit.transform.gameObject;
        }
        else
        {
            if (isActive)
            {
                isActive = false;
                SetPointerColor(isActive);
            }
            if (currContact != null)
            {
                currContact.PointerExit();
                currContact = null;
            }
        }
        if ((currContact != null) && OVRInput.GetDown(OVRInput.RawButton.RIndexTrigger))
        {
            currContact.PointerClick();
        }
        if (OVRInput.Get(OVRInput.RawButton.RIndexTrigger))
        {
            pointer.transform.localScale = new Vector3(thickness * 5f, thickness * 5f, dist);
        }
        else
        {
            pointer.transform.localScale = new Vector3(thickness, thickness, dist);
        }
        pointer.transform.localPosition = new Vector3(0f, 0f, dist / 2f);
    }
示例#2
0
    /*
     * HandlePointerOut: Called whenever the user points away from a gameobject. But only calls object methods if it is a planet or travelMenu.
     * Parameters: object sender - contains method info
     *             PointerEventArgs e - contains the hit information such as the gameobject being collided with
     */
    private void HandlePointerOut(object sender, PointerEventArgs e)
    {
        //Initialize references of the object the laser collided with
        targetObject = e.target.GetComponent <PointableObject>();

        //Check if the pointer stopped pointing at a planet
        if (targetObject != null)
        {
            //Deactivate the laser to be red
            SetPointerColor(false);

            //Have planet stopped reacting
            targetObject.PointerExit();

            //Ensure that the user didn't already click on the menu
            if (isTriggerClickable)
            {
                isTriggerClickable = false;

                //Disable delegate
                controller.TriggerClicked -= HandlePointerClick;
            }
        }
    }