- Home /
Can I access the new Rect Transform Component by code ?
Hello all, I was playing around with the Unity 4.6 Beta, to test out the new UI elements, What I wanted to do is make a menu appear when a button is pressed. I tried to make a smooth Transition of the menu with iTween, but this resulted in strange things, as iTween modifies the normal Transform component. So my question is , is there a way to Access the new Rect Transform by code , so I can make the Transition manually ? or how do you guys animate the UI ?
Thanks alot , T
I'm having the same problem, I can't seem to programmatically move a RectTransform when it's in an Overlay canvas
Answer by Kiwasi · Aug 27, 2014 at 11:06 AM
Yes the RectTransform can be accessed by code.
(RectTransform)transform;
GetComponent<RectTransform>;
It can also be manipulated using the animation system.
Check out the documentation, beta forums, and learn section for further details
Hey thank you a lot ! I will try that out! unfortunately, I did not find a documentation , only the Videos,
could you please provide me with a link ?
It's on your computer, in the Unity documentation folder.
Ok I found what i was searching for :
TheObject.GetComponent<RectTransform>().localposition
BUT I cannot modify the value! I tried it all, assigning a new vector to it, using the Set() method, Setting each axis on its own , nothing works... hów can i modify this value ???:o
I think you can modify the position value by setting it with a new Vector3
e.g.
TheObject.GetComponent().localposition = new Vector3 (1.0f, 2.0f, 0.0f)
Answer by xpkoalz · Dec 01, 2014 at 10:36 AM
If your Canvas Render Mode is set at "Screen Space - Camera" or "Screen Space - Overlay", the Rect Transform component will be uneditable.