- Home /
How to get UI center position on UGUI?
Hi~ I'm using UGUI(Unity 4.6) on my project.
I don't know how to get to the center position of the UGUI.
For example, the figure below.
First I tried using the RectTransform.rect.center.
However, the result is always (0, 0). (An even shift the 'ImageObject' in the figure above, the position (0, 0).)
Secondly tried using the CanvasRenderer.
But when I getComponent the CanvasRenderer 'null reference, an error has occurred.
. CanvasRenderer renderer = GameObject.Find ("ImageObject") getComponent ();
The above code has caused a null reference.
How Would I can get the center position of the UGUI?
Answer by Johnz1234 · Mar 10, 2015 at 02:57 PM
Go to the canvas and select auto scale with the screen and the image will always stay in the place u wanted no matter how big your screen is it will not move
Thank you kindly answer.
This issue has been resolved fooled.
object.transform.position -> This was the coordinates of the center that I want.
Answer by casteponters · Mar 10, 2015 at 06:57 PM
Canvas -> Canvas -> Render Mode -> Screen Space Camera OR use World Space ( if you want adapt size and move ).
Thank you for answers.
Is this the way tell me how to solve given problems with null CanvasRenderer component?