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