- Home /
Question by
inejwstine · May 15, 2013 at 12:04 AM ·
2defficiencycontainsorthello
Raytrace vs Rect.Contains
I'm making a 2D game in Unity using the Orthello plugin. I need to know when the player clicks on a sprite. I can think of two ways to do this.
When the user clicks, use
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
to create a ray, then use Raycast to check if the ray hit a sprite (which can contain a rigid body to collide with).When the user clicks, call
rect.Contains(Input.mousePosition)
once for every sprite, where "rect" is the rectangle that defines the boundaries of the sprite.
Any idea which of the two methods would be more efficient or if the difference between the two would be negligible? Or do you know of a simpler solution? Thanks!
Comment