Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 flowerpowerblubb1990 · Feb 27, 2016 at 10:43 PM · unity 5uipositiontracking

transform position of an UI-image (Unity5)

I want to take the x- and y-position of an gameobject, to set the position of an image in realtime. This is what I have so far:

       float posX;
         float posY;
         public Vector2[] symbPosition;
     
         getSymbolPos(int ID)
         void getSymbolPos(int ID)
         {
             posX = symbPosition[ID].x;
             posY = symbPosition[ID].y;
         }
       
         void Update()
         {
      //here I take the x and y position of the gameobject that can be moved via reactivision-markers
             symbPosition = citygrid.Instance.posTUIO;
             for (int i = 0; i < symbPosition.Length; i++)
             {
                 getSymbolPos(i);
                 if (GameObject.Find("Canvas/Image") != null)
                 {
 //works so far. I get an  output and it changes as soon as I move the object)
                     Debug.Log("blub4: " + posX); 
                     GameObject.Find("Canvas/Image").transform.position = new Vector3(this.posX, 10, this.posY);
                }
             }
 

But the image doesn't move with my gameobject. I think, I can't get access to the rectTransform with .transform.position ... How can I set these parameters for my image? I appreciate any help!! Thank you in advance!

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

3 Replies

· Add your reply
  • Sort: 
avatar image
8

Answer by Pharaoh_ · Feb 27, 2016 at 11:26 PM

GetComponent().anchoredPosition is what you need.

Comment
Add comment · 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
4

Answer by Fydar · Feb 27, 2016 at 11:15 PM

Have you tried using:

 gameObject.GetComponent<RectTransform>().position;

Comment
Add comment · 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
2

Answer by codemaker2015 · Jun 30, 2021 at 02:00 PM

 gameObject.GetComponent<RectTransform>().anchoredPosition = new Vector2(xPos, yPos);
Comment
Add comment · 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

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

8 People are following this question.

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

Related Questions

All UI buttons appear and stack on top of each other. 1 Answer

How to get height of filled image ? 1 Answer

Get position of ui element on canvas 1 Answer

Why is this raycast still hitting ground below a UI button, even after I pass a check to see if finger is above button (as per Unity tutorial) 1 Answer

Button highlighted a pushable without touching it 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