Detect when an entity has been clicked

How do you detect when an entity has been clicked? (programmatically)

Probably the easiest way is to add a collision component and then when you click the mouse do a raycast into the screen from the mouse location. If the ray hits your entity they you have clicked it.

You can see an example of this in the PlayCanvas physics demo, here is the code.

Dave’s original answer is linking to some old URLs that are no longer in existence. However, he has a more recent, and more thorough response here:

I can’t access the code address.

You can find various methods here:

thanks,I had solved the problem.