UnityEngine.Camera.ScreenPointToRay C# (CSharp) Method

ScreenPointToRay() public method

Returns a ray going from camera through a screen point.

public ScreenPointToRay ( Vector3 position ) : Ray
position Vector3
return Ray
        public Ray ScreenPointToRay(Vector3 position)
        {
            Ray ray;
            INTERNAL_CALL_ScreenPointToRay(this, ref position, out ray);
            return ray;
        }

Usage Example

コード例 #1
0
        private void ClickingOnUnitsAndStructures()
        {
            m_BoxStartPos = m_MousePosition;

            var ray = m_Camera.ScreenPointToRay(m_MousePosition);

            if (Physics.Raycast(ray, out var s_Hit, Mathf.Infinity, m_StructureMask))
            {
                // Click on blueprint prefab, return to avoid error on mouse callback
                if (s_Hit.transform.TryGetComponent(out BuildComponents _))
                {
                    return;
                }

                if (s_Hit.transform.parent.parent.TryGetComponent(out IStructure structure))
                {
                    ClickOnBuilding(structure);
                }
            }

            if (!Physics.Raycast(ray, out var u_Hit, Mathf.Infinity, m_UnitMask))
            {
                return;
            }

            if (u_Hit.transform.parent.TryGetComponent(out IUnit _))
            {
                ClickOnUnit(u_Hit.transform.parent.gameObject);
            }
        }
All Usage Examples Of UnityEngine.Camera::ScreenPointToRay
Camera