예제 #1
0
    // Update is called once per frame
    void Update()
    {
        RaycastHit hit;
        Ray        ray = camera.ScreenPointToRay(new Vector3(Screen.width / 2f, Screen.height / 2f, 0));

        if (Physics.Raycast(ray, out hit))
        {
            Highlightable target = hit.transform.GetComponent <Highlightable>();
            if (target != highlighted)
            {
                if (highlighted != null)
                {
                    highlighted.Deselect();
                    if (highlighted.transform.parent == KeyBook.transform)
                    {
                        controller.lookingAtBook = false;
                    }
                }
            }
            if (hit.transform.parent == KeyBook.transform)
            {
                controller.lookingAtBook = true;
            }
            if (target != null)
            {
                target.Highlight();
                highlighted = target;
            }
            // Do something with the object that was hit by the raycast.
        }
        else if (highlighted != null)
        {
            highlighted.Deselect();
        }
    }
예제 #2
0
 // Update is called once per frame
 void LateUpdate()
 {
     Collider[] hitColliders = Physics.OverlapSphere(pickUpOffset.x * transform.right + pickUpOffset.y * transform.up + pickUpOffset.z * transform.forward + transform.position, pickUpRadius, pickUpLayer);
     foreach (Collider collider in hitColliders)
     {
         Highlightable highlightableScript = collider.GetComponentInParent <Highlightable>();
         if (highlightableScript != null)
         {
             if (highlightableScript.highlighted == false)
             {
                 highlightableScript.Highlight(highLightColour);
                 return;
             }
         }
     }
 }