- Home /
Question by
apdNinja · May 08, 2011 at 08:23 PM ·
raycastcollidergameobjects
Using a raycast or collider on my weapons...
How can i get information on what it hit? Such as the objects name, or tag?
Comment
Best Answer
Answer by Dave 11 · May 08, 2011 at 09:33 PM
Try this:
var hit : RaycastHit;
Debug.Log("You hit: "+hit.collider.gameObject.name);
It should return whatever gameObject you hit. Ofcourse don't forget to add hit to your Physics.Raycast
Physics.Raycast (origin : Vector3, direction : Vector3, out hitInfo : RaycastHit, distance : float = Mathf.Infinity, layerMask : int = kDefaultRaycastLayers
Best Answer
Answer by Zetsaika · May 08, 2011 at 08:26 PM
You can use RaycastHit for Raycasts and use collider.transform.name or .tag. Search scripting reference for these.