I'm trying to set up UI elements that are instantiated from prefabs. I use SetParent
to put them under a UI elements that's directly under the Canvas. The issue is that when the UI scales, these prefabbed elements don't stick to the part of the screen where they need to be.
The Canvas is set to Scale with Screen Size and I'm only interested in 16:9 screens, no mobile stuff.
Is there a standard way of placing these instanced prefabs so their relative position to everything else would stop changing with the screen resolution?
statFlag = Instantiate(_infoBox);
statFlag.GetComponent<RectTransform>().position = gameObject.GetComponent<RectTransform>().position + new Vector3(-50, -250 - _displayedStats.Count * 50, 0);
statFlag.transform.SetParent(transform, true);
statFlag.transform.localScale = new Vector3(1/statFlag.transform.lossyScale.x, 1/statFlag.transform.lossyScale.y, 1/statFlag.transform.lossyScale.z);