How do I know I clicked on a Gameobject in Unity?

Asked

Viewed 1,069 times

3

I’m trying to create a game similar to Fruit ninja, but I know little of game programming, I understand code c#, could tell me a method if I clicked on a gameobject?

  • Is the game for mobile devices? For desktop?

2 answers

3

0

You should add a Collider to your Gameobject and tag. After adding Collider and tag, in the script linked to your Gameobject you can do the following:

function OnCollisionEnter (c : Collision){
   if(c.gameObject.tag == "meuObjeto") {
     // Faça alguma coisa.
   }
}
  • 1

    Incomplete answer, not dealing with the click part, and the event that should be used to treat a click is not this...

  • True. I made a little mistake, the Oncollisionenter is to treat collisions between objects. Thank you for the correction.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.