spawn particle at middle of recttransform via script

Hi,

I have a lot of rec-transforms and i would like to spawn a particle via script at the middle of a specific rect-transform.
The pivots of the transforms all differ so I would need to calculate the middle of the rect based on the pivots.

recttransform.rect.center only give me the local.
But I would need the center position of the recttransformin in screenspace.

I’m using “Screenspace - Camera”.

Anybody has an idea on how to do that?

SOLUTION found, if anybody needs it.

I’m extending the RectTransform in this code.

    public static Vector3 GetWorldRectCenter(this RectTransform trans) {
        Vector3 pos = new Vector3 ();
        Vector3[] corners = new Vector3[4];
        trans.GetWorldCorners (corners);
        // 0 - left bottom
        // 1 - left top
        // 2 - right top
        // 3 - right bottom
        pos.x = corners [1].x + ((corners [2].x - corners[1].x)/2);
        pos.y = corners [1].y + ((corners [0].y - corners[1].y)/2);
        return pos;
    }