- Home /
 
 
               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
              
 
               
              Answer by Fydar · Feb 27, 2016 at 11:15 PM
Have you tried using:
 gameObject.GetComponent<RectTransform>().position;
 
              Answer by codemaker2015 · Jun 30, 2021 at 02:00 PM
 gameObject.GetComponent<RectTransform>().anchoredPosition = new Vector2(xPos, yPos);
 
              Your answer