Hi, I am trying to destroy a 2D object by just clicking on the image but it does not work. IS there a setting that you need or component that needs to be added when creating a "D U>I element to enable it to be inter-actable via a mouse click as my debug is not even returning a message.
What have you done so far for your destroy-on-click behaviour?
Common mistake is not including the EventSystem gameobject in the scene.
Another possibility is having RaycastTarget set to false on your button UI object.
Hi
Could you show me your “Hierarchy”, “Inspector”, “Script code”?
sorry for the misunderstanding, its not a button, its a U.I image
and here’s the code:
void OnMouseDown()
{
Debug.Log("I have been clicked YAYAYAYYAYA ");
}
also does it matter if another object in the scene has the Onmousedown function attached to it on another script?
Hi
Since its just a ‘Raw Image’ element, it doesn’t have interactivity. You could either :
1). Use UI Events and Triggers : UI Components - Unity Learn
2). Simply use a UI Button element, although I’m not sure if the button’s event trigger will allow a Destroy() of the button itself(can be quickly tested out though)
is there no possible way to give the raw image a level of interactivity?
Yes, it can be given n thats what I meant by option 1
