Hi, I have the following code that successfully instantiates a prefab button object. I see the button pop up in the scene-hierachy, but it's way outside the ui canvas coords and it is NOT parented to the canvas (and thus invisible)
public Canvas canvas;
public GameObject prefabButton;
//in start!
GameObject gameobject = Instantiate(prefabButton) as GameObject;
gameObject.transform.SetParent(canvas.transform, false);
gameobject.SetActive(true);
While debugging I see that the canvas pointer is set, and is of the type: canvas. Also, I have only one canvas in the scene. Any ideas?
↧