Game Development Reference
In-Depth Information
Figure 7-18. The menu of the various Gizmo selections that can be viewed in the Game view
The various Raycast methods give you control over which colliders the ray can hit, and whether or
not you want information back regarding the collider hit by the raycast.
In the editor, turn the player character around by changing the Transform.rotation y coordinate
to 180. Create five primitive sphere objects and give them transform.position s of (0, 0.5, -5),
(4, 0.5, 5.5), (0.7, 0.5, -4), (-3, -0.5, -11) and (-4, 0.5, -2). Using standard naming conventions,
name them sequentially Sphere_001 to Sphere_005. In MonoDevelop edit your RaycastFun script to
the following:
function Update () {
var hit : RaycastHit;
if(Physics.Raycast(transform.position + Vector3(0, 0.5, 0), transform.forward, hit))
{
print ("Collided with game object " +
hit.collider.gameObject.name);
}
}
 
Search WWH ::




Custom Search