How to Instantiate at a specific position of the parent Canvas

The Vector3 doesn’t seem to have anything to do with the parent Canvas

Instantiate(unitUIPrefab, anchoredPOsition3D, Quaternion.identity,parent); 

I then expect to use anchoredposition3D to make these instantiated UIs stay in relative position at 16:9 aspect ratios, form a queue between them and keep them at the same intervals, and then they can move freely.

What parameter should I use for the position of Instantiate’s Vector3?

1 Answer

1

Instantiate gives you a reference to the GameObject you’ve instantiated. You can then set the anchored position after you instantiate it.

GameObject go = Instantiate (prefab, anchoredPOsition3D, Quaternion.identity, canvas.GetComponent<RectTransform> ()); 
go.GetComponent<RectTransform> ().anchoredPosition3D = anchoredPOsition3D;