Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by nishant619 · Jun 15, 2017 at 07:51 AM · uitransform.position

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);

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by IgorAherne · Jun 15, 2017 at 12:01 PM

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

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image nishant619 · Jun 15, 2017 at 12:20 PM 0
Share

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.

avatar image NoseKills nishant619 · Jun 15, 2017 at 02:59 PM 1
Share

Your ui doesn't use the same coordinate system as objects in the world. You can use RectTransformUtility to make the conversions to and from canvas/world/screen space.

If you want ui objects to appear one under the other though, you should probably just be using a VerticalLayoutGroup component in the object that parents those items ins$$anonymous$$d of writing your own code for it.

avatar image nishant619 NoseKills · Jun 16, 2017 at 08:55 AM 0
Share

thanks a lot man!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

107 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

I'm trying to displace a UI object in the opposite direction I move a scrollbar 1 Answer

Prefab Instance changing when loading scene in editor 0 Answers

Screen position of the uGUI object that deep in hierarchy 0 Answers

How can I accurately convert a Game Object's position to a sub Canvas/Rect screen position? 0 Answers

RectTransform.TransformPoint returning zero everytime after Unity 4.6.3 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges