- Home /
Question by
fedqx · Oct 19, 2017 at 02:59 PM ·
unity 5raycastunity5getmousebuttondown
what is the difference between raycast and getmousebuttondown in a RTS game ?
they both are doing the same job when i use them in selection of an unit(soldier) so what is the difference ?
Comment
Answer by Kishotta · Oct 19, 2017 at 04:18 PM
These two things are really not the same at all (though they can be used to achieve similar effects).
Input.GetMouseButtonDown is true only on the frame during which the specified mouse button is pressed.
Physics.Raycast is true only when a ray extending from some origin in some direction for some distance meets a collider (on some layer). If no collider is detected, it is false.
These two methods give you vastly different information about the current state of your game/application.