Exemplo n.º 1
0
        public static RaycastHit2D[] SpokeCastAll2D(Vector2 origin, int nRays, float range = float.MaxValue, ArrayOps.Filter <RaycastHit2D> filter = null)
        {
            if (nRays == 0)
            {
                throw new ArgumentException("Number of raycasts cannot be zero.");
            }

            List <RaycastHit2D> hits = new List <RaycastHit2D>();

            for (float currentAngle = 0f; currentAngle < 360f; currentAngle += 360f / nRays)
            {
                hits.AddRange(RaycastAll2D(origin, Quaternion.Euler(0f, 0f, currentAngle) * Vector2.right, range, filter));
            }

            return(hits.ToArray());
        }
Exemplo n.º 2
0
        public static RaycastHit2D[] RaycastAll2D(Vector2 origin, Vector2 direction, float range = float.MaxValue, ArrayOps.Filter <RaycastHit2D> filter = null)
        {
            RaycastHit2D[] output = Physics2D.RaycastAll(origin, direction, range);

            if (filter != null)
            {
                output = filter(output);
            }

            return(output);
        }