How to instantiate prefab inside UI canvas From Script | Unity

preview_player
Показать описание
Using C# this video is to show how to add prefab in the User Interface canvas unity using C#
Рекомендации по теме
Комментарии
Автор

thanks very much, your video helps me

heartice
Автор

Great, Thank you.

I had a look at some of the overloads of Instantiate & found that the below also works.

public GameObject clone; //prefab to clone
public GameObject parent; //parent of clone

Instantiate(clone, parent.transform);

thecompletionist
Автор

What if your canvas needs to be set to World Space - Overlay?

I have just about the same code and setup as you but in 2d and overlay. that wont make prefabs show up in or outside of the canvas.
there's something with the camera z level I think but not sure. I see the clones showing up in hte hierarchy but they're not visible.

MindGem
Автор

why can't i write "transform" after "("aaaa")?

radkarbonat
Автор

If Youtube would let me... I would give you 1000 of dislikes for that noisy music

davidgtriana