How can I make a game object click event? I know how to make a GUI click event, but I can’t figure out how to do the same for Game Objects. Here’s an example of what I want to do.
Lets say that I have a game object, and in it, is a box sprite. I also have another game object which is the background. I created a script which creates a click event. What I want is the click event to happen on the box. Here a code example:
Now, when I made this script I put it in the box game object. Now, when I run it, It does work. It responds to when I click, but I want it to respond ONLY when I click the box. Because if I click anywhere, it still responds. How do I make it only respond to one spot. How can I do this?
Also, I have found ways to do this online, and it does work, but the problem is that the game I am working on makes the game object move. I found an online script that would create an invisible box around the game object and it respond to only that spot, but when I move the game object around the invisible box doesn’t follow. Is there a way to make the invisible box follow the game object? Here’s the invisible box code I found: