- Home /
Getting raycasting info from mouse event (eg through RaycastHit)
Unity usually feeds some context information for events as required. Collision events get fed the Collision
class, network events their respective data structures, etc. Even info not explicitly passed can be accessed from static properties or methods (eg Time
class, Camera
class). Is there a way to get the raycasting info that originated a mouse event? It feels awkward to need to perform a new raycast to get the collider or the normal, inside an event that was supposedly trigger by what I reckon was an identical raycast.
Well like do you mean getting the info of an object that you click on? Anyways, raycast info is stored in the RaycastHit variable. I dont really get what's so problematic.
I meant getting the info of the raycast that was just performed. It's not "so" problematic, just shaggy.
Oh no, I was thinking about $$anonymous$$onoBehaviour special methods like On$$anonymous$$ouseDown, OnDrag, etc
Well that's because On$$anonymous$$ouseDown() is only called on the collider that the mouse clicked on. You don't need the collider info because you ARE the collider in that instance.