button objects generated by instantiate

Asked 2 years ago, Updated 2 years ago, 92 views

Is there a way to button objects generated by instantiate??

Specific steps are to remove the generated object and click the button to remove the object.
That's it

I prefab it and put spriterender and button

There was no button function when I tried above

For some reason, what you generated by instantiate cannot be displayed on the image and can only be displayed on the spriterender, so
I use the latter one.

c# unity3d

2022-09-30 20:12

1 Answers

Is the image generated by Instantiate a child of the object with the Canvas component?
 To view the image components of the UI, they must be located below the Canvas component.
 
 As for the lack of function as a button, I think there is no EventSystem on Hierarchy.
 EventSystem is required to determine button input.
 You can create it in GameObject>UI>EventSystem in the menu at the top of Unity.
 
 Canvas and EventSystem are automatically created when UGUI objects such as Button and Image are created on the Editor.
 If you want to generate Button or Image at runtime, you must search for Canvas on Hierarchy to make it a child object or check for EventSystem.
 Or I think we need to instantiate Canvas and EventSystem as well.


2022-09-30 20:12

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.