Exemplo n.º 1
0
    /// <summary>
    /// Returns the object casting the shadow if the position is in its shadow
    /// </summary>
    /// <param name="position"></param>
    /// <returns></returns>
    public static GameObject InShadow(Vector3 position, LayerMask layerToCheck)
    {
        Debug.Log("Checking shadow");
        List <GameObject> lightsInRange = lightManager.GetLightsInRange(position);

        for (int i = 0; i < lightsInRange.Count; i++)
        {
            RaycastHit hit;
            var        heading   = position - lightsInRange[i].transform.position;
            var        direction = heading / heading.magnitude;
            Debug.DrawRay(lightsInRange[i].transform.position, direction * lightsInRange[i].GetComponent <Light>().range);
            if (Physics.Raycast(lightsInRange[i].transform.position, direction, out hit, lightsInRange[i].GetComponent <Light>().range, layerToCheck))
            {
                if (hit.point != position)
                {
                    return(hit.collider.gameObject);
                }
            }
        }

        return(null);
    }