transform.position vs interface position

I am working with Canvas and prefabricated Text. Through script i want to place the text one below the other. The problem is that obj.position += new Vector(0,33,0); where 33 is height of the object, is not actually 33 when looking at the inspector.

even translation of 1 through script is 38.5 in inspector. WHY?

here is the code

selfTransform = this.transform.gameObject.GetComponent<RectTransform>();
selfTransform.position = new Vector3 (0, 1, 0);

1 Answer

1

You need to look into RectTransform. Usually (definitelly in your case, unless your text is a 3D mesh, which it’s not by your words) you need RectTransform. This component is by default swapped instead of traditional Transform, on all children of UI Canvas

To access it you would have

RectTransform _rectTransform = transform as RectTransform;
_rectTransform.pivot += Vector2.one*0.1f;  //etc

m sorry, but i have been using RectTransform only. the code was not properly displayed, hence the confusion, but now i formatted it. As you can see, m using RectTransform only. Further more, the problem is not just here, even if i scale something to a value, it won't be scaled to that value, some other value is seen on runtime. I tried creating a new project, same issue. If i make x position into 30 using script, on runtime, i should see it at 30 right? m thinking of reinstalling unity, but then i'll have to set everything up again.

–