I’m having a bit of an issue doing this. I have a prefab I want to instantiate and I’m doing the following:
var newButton = (GameObject)GameObject.Instantiate(part); var myTransform = GetComponent<RectTransform>(); var btnTransform = newButton.GetComponent<RectTransform>(); btnTransform.SetParent(transform.parent.GetComponent<RectTransform>()); btnTransform.position = Vector3.zero;//GetComponent<RectTransform>().position;
I’ve tried to fiddle around with different values, but what happens is that the button turns out HUGE, instead of being properly in the camera space. How do I need to do this parenting to make the button show up properly sized. In the hierarchy, it appears to be the child of the correct Canvas object.