예제 #1
0
    public static List <Enemy> GetEnemiesAroundPoint(Vector2 point, float radius)
    {
        var fromCell = Instance.GetIndicesByPosition(point - new Vector2(radius, radius));
        var toCell   = Instance.GetIndicesByPosition(point + new Vector2(radius, radius));
        var result   = new List <Enemy>();
        var pointv3  = new Vector3(point.x, point.y);

        for (var i = fromCell[0]; i <= toCell[0]; i++)
        {
            for (var j = fromCell[1]; j <= toCell[1]; j++)
            {
                foreach (var enemy in Instance._grid[i][j])
                {
                    if ((enemy.transform.position - pointv3).magnitude <= radius)
                    {
                        result.Add(enemy);
                    }
                }
            }
        }
        return(result);
    }