How do I transform/resize a polygon from within a C# Script Component?

Hi Everyone!

I’m currently trying to set up a script that transforms/resizes a polygon drawn the GUI Canvas from within a C# Script within the same object. The Polygon itself is drawn using CiaccoDavide’s [Unity-UI-Polygon Extension][1], which appears to house a regular Rect Transform Component.

Basically, what I’m trying to do is made a script that grows/shrinks a polygon depending on a relationship between two variables. The ‘base’ size of the Polygon is 248x248, and so the (general) formula I’m working with is:

width = (breathCount / breathCountMax)*248;
height = (breathCount /breathCountMax)*248;

I’ve been hunting around various tutorials and queries about Transform, RectTransform, and all kinds of things, but without much (any) luck at all. In the interests of full disclosure, this is my first attempt at a Unity Project (coming from GameMaker), and so I’m probably a little over my head for now.

SO far my attempt has looked like this (along with some subtle deviations, none of which worked):

public class breathTransform : MonoBehaviour
{

    // Start is called before the first frame update

    GameObject obj;
    public RectTransform rT;


    void Start()
    {
        obj = GameObject.Find("breath_UI_cur");
        rT = obj.GetComponent<RectTransform>();
    }

    // Update is called once per frame
    void Update()
    {
        rT.sizeDelta = new Vector2((rT.sizeDelta.x * ((breathing.breathCount / breathing.breathCountMax) * 248)), (rT.sizeDelta.y * ((breathing.breathCount / breathing.breathCountMax) * 248)));
    }

Any help is greatly appreciated, as this query is boggling my mind! It’s something that’s relatively simple in GameMaker, but I can’t wrap my head around it yet in Unity!
[1]: GitHub - CiaccoDavide/Unity-UI-Polygon: Polygon renderer for the new Unity UI

@CitronMW, I believe it will be easier setting the local scale.

If the base size is 248. then the scale you need in any dimension will be desired size/248. So set those for x and y, for z you can use 1 because UI elements don’t have a z size, per se.

for example,

float scaleX = desiredXSize/248;
float scaleY = desiredYSize/248;
rT.localScale = new Vector3( scaleX, scaleY, 1 );