1
\$\begingroup\$

So, I am trying to make a simple GUI Instantiate system. The GUI is going to spawn successfully, but the position is wrong.

Position : (Left, Right: 249.8423 ; Top, Bottom : 400) 
Anchors : (Min: X:0 Y:0 ; Max: X:1 Y:1) 
Pivots : (X:0.5 Y:0.5) 
Rotation : (X:0 Y:0 Z:0)
Scale : (X:1 Y:1 Z:1) always...

My Code :

    GUIPausePopup pause = UI.Create<GUIPausePopup>(GameObject.Find("Canvas"));
    //Spawn and set parent(Canvas)
    pause.GetComponent<Transform>().gameObject.SetActive(true);
    //Working without any issues.


    //Position system not work. I don't know why.
    pause.GetComponent<RectTransform>().anchoredPosition3D = new Vector3(0f, 0f, 0f);
    pause.GetComponent<RectTransform>().anchoredPosition = new Vector2(0f, 0f);
    pause.GetComponent<RectTransform>().localPosition = new Vector3(0f, 0f, 0f);
    pause.GetComponent<RectTransform>().position = new Vector3(0f, 0f, 0f);
    pause.transform.position = new Vector3(0f, 0f, 0f);
    pause.transform.localPosition = new Vector3(0f, 0f, 0f);

Thanks for help...

\$\endgroup\$
  • 2
    \$\begingroup\$ Unity UI layouting problems are notoriously hard to troubleshoot without a complete picture of everything that is happening in the UI... Are there any layout-related components on the object or one of its parents? \$\endgroup\$ – Philipp Jun 2 '16 at 14:05
  • \$\begingroup\$ pretty sure you need to set anchorMin and anchorMax before seeting anchoredPosition. \$\endgroup\$ – Uri Popov Jun 2 '16 at 14:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.