About the Instantiate problem inside canvas
hi all guys, i got a problem about the clone.
I would like to Instantiate an object in scene, it's work for me like the photo below ,i can clone a table outside canvas.
But the problem is, how can i Instantiate all clone tables inside canvas?
my clone table script in below , please help, thanks. :
Answer by streeetwalker · Sep 13, 2020 at 06:58 AM
@kimkim0914, you want your instantiated object (clone) to be the child of another object.
In your example, do to that you need a reference to the parent transform (in your example, the RectTransform of the canvas) and the child.
Assuming you get a reference to the canvas RectTrasform in a variable, 'canvasTransform', and that your clone reference is a GameObject (it's not explicit in your code) then you will simply code this:ItemToSetIntoPlacer.transform.parent = canvasTransform
That will make your cloned object a child of the canvas. You'll have to fiddle with the location of the cloned object after that.
Your answer
Follow this Question
Related Questions
How can I organize menus as a tree hierarchy? 0 Answers
Prevent gameobject go off screen 0 Answers
Having trouble moving a GameObject to another scene and Transform it to a different position 0 Answers
instantiate prefab at every gameobject with tag 0 Answers
Problem with destroying a gameobject 2 Answers