Hello everyone, I’m attempting to make a 2D clicking game and I’m really new to this kind of thing. I was just wondering how to make a 2d sprite appear randomly somewhere on the screen and then disappear when it’s clicked on. I’d then also like to make it re-appear somewhere else but this time 2 of the sprites appear and the when they’re both clicked on 3 of the same sprite appears until they’re all clicked on, and so on. If anyone can help me out with this you’ll be a massive help to me.
You will need to create a script to spawn the sprites. If you create a sprite GameObject and then make a prefab of it, you can use Instantiate() in order to create clones of the prefab. You would then need to do a Raycast when the user clicks. So you check for the MouseDown and then Raycast to find out if you hit a sprite. Give the prefab sprite a “Tag” and check to make sure the RaycastHit’s tag matches that of the sprite clone. If it does, call Object.Destroy. Keep track of how many sprites were created each time and when the number gets to zero, Instantiate more.