- Home /
How to set PosX and PosY in runtime UGUI
Hi I am trying to access the rect transform's posX and posY via script for the new UGUI.
I have tried:
RectTransform m_loadingRectTransform = m_loadingScreen.GetComponent<RectTransform>();
m_loadingRectTransform.position = Vector3.zero;
//or
m_loadingScreen.transform.position = Vector3.zero;
//or
m_loadingRectTransform.transform.position = Vector3.zero;
But none seem to work
Thanks for the comment but m_loadingRectTransform.position = new Vector3(0,0,0); doesn't seem to work
I have tried it and it still does not work it gives me the same position where I instantiated it.
Answer by deeds0l · Dec 01, 2014 at 07:08 AM
I figured out that the problem was that I was supposed to set local position instead of position.
m_loadingRectTransform.localPosition = new Vector3(0, 0, m_loadingRectTransform.localPosition.z);
Answer by Michio-Magic · May 23, 2015 at 07:52 AM
This worked for me :
(Javascript)
var messageText: UI.Text; // the actual Text in the Canvas
public static var message : String = "smooth scrolling ...";
public static var scrollx : float;
//=============== main game overlay ==================
if (scrollx<20) scrollx=800;
//============= scrolling message ================
if (message !="") {
messageText.text=message; // change the actual Text
scrollx -=10;
messageText.transform.position.x = scrollx;
}
Answer by M-G-Production · Dec 01, 2014 at 06:31 AM
Hi deeds0l!
Hmmmmmm... You don't seem to want to set the Transform.Position of an GameObject, but a RectTransform Component... It's quite different...
Try replacing Vector3.zero with "new Vector3.Zero"or "new Vector3(0,0,0)"
ex: m_loadingRectTransform.position = new Vector3(0,0,0);
Math
Actually, It's look more like a Vector2(x,y) then a Vector3... I'm not sure, I never used RectTransform.. Anyway, trying to help!
Thanks for the comment but changing it to m_loadingRectTransform.position = new Vector3(0,0,0); does not work nor does Vector2(0,0)
Answer by Helical · Dec 01, 2014 at 07:10 AM
m_loadingScreen is probably a canvas which means you can't move it about. Try moving a button, if you succeed then move a panel which holds all your loadingScreen information.
Your answer