Why both images disappear when clicked on only one?

Hey guys!

I’m making a game where you need to find images, click on them, they disappear and when all of them are gone, you go to the next level.

As you can see on screenshots, I have two images (ball and disk) and when I click on one of them, both disappear instead on this one and I’m not sure why.

They both have the same script attached “ItemStatus” in which you have a method to destroy the image when clicked on. Also, it calls a method (from the script “Level”) to count the number of images (the method is named CountItems()) as well as calls a method (DecreaseNumberOfItems) when the image is destroyed to decrease the number. When it is 0 (which means no images left), the game is finished and it loads next scene.

Unfortunately, like I said above when I click on one image and both disappear (and the next scene is loaded). Could you help me fix it so only the particular image disappear when I click on it.



The input system detects user input in general, and is not relative to each individual MonoBehaviour. So when Input.GetMouseButtonDown is true in one context, it’s true in every context.

What you probably want to use instead is OnMouseDown.

Now it’s working, thanks!