- Home /
Question by
tucna · Oct 06, 2015 at 06:38 PM ·
performanceraycastingmousedown
Raycasting vs. events
Hi,
I need to move camera towards an object. Let me say that I have a scene with the 4 cubes and with camera nearby. I need to click on some cube and move. For target position determination, I can use:
1)
Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hitInfo)
and check what cube was hitted by the ray, or
2) create script with
MonoBehaviour.OnMouseDown()
and attach it to the each cube.
What solution is better from performance (or whatever) point of view? Is there any reason for the prefering one of them?
Thank you.
Comment
not sure but i think 2 variant is better for your situation. You can do input events without inspector with only scripting if this is easier for you.
Well, can you say in general what situations are better to solve via 1) and what via 2)?