How to change the Top and Bottom (rect.yMin and yMax) properties of a rectTransform, in a script?

Hey guys. I made an image (with child images and buttons and what not) and made it a prefab. I am not trying to Instantiate it, however when I do, its transform info is all messed up. No problem, I can fix that manually in the code right after I instantiate it!

(NOTE: My image has the anchors at the corners of the image, NOT next to each other. That matters)

I’ve figured out that:

  • localPosition = how to change posZ
  • sizeDelta = how to change Left and Right
  • localScale = how to changescale

but HOW do you change Top and Bottom? I know how to READ them (rectTransform.rect.yMin and yMax), but how to I CHANGE them?

I think that one should help.

take a look at anchoredPosition and anchoredPosition3D, use it like this:

text.rectTransform.anchoredPosition3D = new Vector3(my_new_x, my_new_y, my_new_z);

Not sure if this will help but it fixed an issue I had with a camera not pointing in the normal UI way, as in I have a menu that can show 3D items on Unity indy which means having a camera pointing down from the terrain. However it also deals with spells which are just prefab panels.

When I switched the new UI it was displaying them edge on! Anyway try this:

transfrom.localRotation = Quaternion.Euler(0.0f,0.0f,0.0f);