EnemyFormation width

Hi guys,

Don’t you know any clever way how to compute total EnemyFormation width?

ok I came up with my own solution:

private Bounds GetMaxBounds(GameObject g) {
        var b = new Bounds(g.transform.position, Vector3.zero);
        foreach (Renderer r in g.GetComponentsInChildren<Renderer>()) {
            b.Encapsulate(r.bounds);
        }
        return b;
    }

And float halfWidth = GetMaxBounds(gameObject).size.x / 2; returns width (y for height).

Hi @pepavesely,

Nice solution.

This is only adding the widths of the sprites together though, e.g. if you don’t have your enemy ships next to each other in the formation, you would also need to consider the spaces in between?