Hello, I am trying to spawn an image of coin everytime I click on button, everything works except it keeps making clones behind actual Canvas which means I am unable to see the image
Also is there a way to spawn(Instantiate) it between two objects in Canvas hierarchy so that one is over the prefab and one is behind the prefab?
Thank you for any help

When you instantiate something, you can assign it to a parent which get it to spawn under that parent object. In the case of a canvas, then you would want it under that canvas if it’s a UI component.
Not sure what you are asking about one over and one under.
When you call instantiate you can provide a Transform that will be the parent of the newly instantiated object:
var myNewObject = Instantiate(myPrefab, theParentTransform);
You can also rearrange an object in the hierarchy by calling SetSiblingIndex
.
// This will set the object to be the first child of its parent.
myObject.transform.SetSiblingIndex(0);
1 Like