예제 #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
    /*
     * HandlePointerIn: Called whenever the user points at ANY 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 HandlePointerIn(object sender, PointerEventArgs e)
    {
        //Initialize references of the object the laser collided with
        targetObject = e.target.GetComponent <PointableObject>();

        //Check if the pointer is pointed at a planet
        if (targetObject != null)
        {
            //Activate the laser to be green
            SetPointerColor(true);

            //Have planet react to the pointing
            targetObject.PointerEnter();

            //Ensure that the user didn't already click on the planet
            if (!isTriggerClickable)
            {
                isTriggerClickable = true;

                //Set a delegate so that the user can click on the planet as long as they are pointing at it
                controller.TriggerClicked += HandlePointerClick;
            }
        }
    }