How do I know that I clicked on a GameObject on Unity?

3

I'm trying to create a game similar to fruit ninja, but I know little about game programming, I understand c # code, could you tell me a method of clicking on a gameobject?

    
asked by anonymous 26.02.2016 / 16:29

2 answers

3

Add a Collider (any type), do not mark as "Is Trigger", and add that code to your script:

void OnMouseDown()
{
    //clicaram em mim
}

It makes a raycast from the point of the camera in the direction of the click.

References: link

    
26.02.2016 / 20:17
0

You should add a collider in your GameObject and a tag. After adding the 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.
   }
}
    
26.02.2016 / 17:56