I want to change the size of an UI image to match exactly the size of a rectangle that I create in real time, I tried the code below but the image is not aligned with the rectangle as you can see in the screenshot. How can I fix that?
Script:
public Image MyImage;
void Update () {
Rect boundsDown = new Rect(0, Screen.height / 35, Screen.width / 1.05f, Screen.height /3);
MyImage.rectTransform.sizeDelta = new Vector2(Screen.width / 1.1f, Screen.height / 3);
MyImage.transform.position = boundsDown.position;
}
This is the result: