Beispiel #1
0
        private bool CheckLookAndRange()
        {
            //Raycast
            Ray cameraRay;

            if (m_useNonCamObjAsPointer)
            {
                cameraRay = m_MainCamera.ScreenPointToRay(m_MainCamera.WorldToScreenPoint(m_NonCamPointer.transform.position));
            }
            else
            {
                cameraRay = new Ray(m_MainCamera.transform.position, m_MainCamera.transform.forward);
            }

            RaycastHit staringAtWhat;

            Physics.Raycast(cameraRay, out staringAtWhat, Mathf.Infinity, m_raycastLayerMask);
            //check if the raycast hit a clickable object
            if (StaringAtClickableObject(staringAtWhat))
            {
                ClickableObject tempObject = staringAtWhat.collider.gameObject.GetComponent <ClickableObject>();
                if (CheckPlayerRange(tempObject))
                {
                    SetObject(tempObject);
                }
                else if (m_lookingAtClickableObject)
                {
                    UnsetObject();
                }
            }
            else if (m_lookingAtClickableObject)
            {
                UnsetObject();
            }

            return(m_lookingAtClickableObject);
        }