- Home /
Question by
saberboy117 · Jul 10, 2011 at 01:11 AM ·
gameobject
Getting gameobject from raycast hit
I am wondering how I can get the gameobject of the object my ray cast hit? the transforms parent dosent give it.
thanks
Comment
Best Answer
Answer by Joshua · Jul 10, 2011 at 01:28 AM
Well.. you look up RaycastHit and see you can use .transform to get the Transform. You next look up Transform and see that gameObject is one of it's variables. So there you go.
RaycastHit.transform.gameObject : GameObject
An example to easy things:
if (Physics.Raycast(cam.ScreenPointToRay(...), hit){
Destroy(hit.transform.gameObject);
}