- Home /
Question by
The-BOOM · Mar 13, 2010 at 09:05 PM ·
gameobjectraycast
Selecting through raycast
I want to get the object that was hit by a ray, but can't find out how. Help?
Comment
Best Answer
Answer by Jason_DB · Mar 13, 2010 at 09:39 PM
You could use raycastHit to get the object:
var hit : RaycastHit;
var object : GameObject
if (Physics.Raycast (transform.position, -Vector3.forward, hit)) {
object = hit.collider.gameObject
}