Friday, April 12, 2024
HomeGame Developmentunity - A number of objects with OnMouseDown VS Raycasting: Is one...

unity – A number of objects with OnMouseDown VS Raycasting: Is one higher than the opposite?


Behind OnMouseDown, Unity is reworking your mouse place from window coordinates to view coordinates, projecting into the world utilizing the view-projection remodel and testing this ray in opposition to Colliders which have the best “layer masks” for OnMouseDown receivers.

You need to be capable of see what it truly calls to do that within the profiler. It is most likely simply precisely would need to do if you’re utilizing Colliders or Unity’s physics module extra usually. IIRC it makes use of RayCast.

A motivation for doing it your self can be that you could specify a layer masks when calling RayCast, in order that fewer Colliders are examined, which may benefit efficiency.

One other motivation might be that you just need to take management of when precisely the ray checks occur, fairly than provide a callback to an opaque system, whether or not for efficiency or simply choice.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments

Arnavsijapati on Planet of Lana – Beta Demo
Jai Kishor Upadhyay on Planet of Lana – Beta Demo