Game Development Reference
In-Depth Information
Layers
Whereas tags reduce bulky code by addressing groups of game objects, Layers also address groups
of game objects. They help in terms of game performance because they are most commonly used
as a constraint to selectively ignore groups of game objects or areas of the scene, which reduces the
processing load.
Layers can be used to limit which part of a scene will be rendered by a camera, for layer-based
collision detection, or to determine which areas of a scene will be illuminated, again reducing the
processing load. Unlike Tags, the first seven layers are required by Unity and you are limited to a
total of 31 layers.
If you comment out or edit your code in the RaycastFun script's Update() function 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);
Destroy(hit.collider.gameObject);
}
}
once again the platform and block obstacles the ray detects are destroyed along with the spheres.
Select Obstacles in the Hierarchy. In the Inspector, to the right of the Tag menu select the Layer
drop-down menu and choose Ignore Raycast (Figure 7-21 ).
Figure 7-21. Select Ignore Raycast in the Layer drop-down menu
A pop-up window will ask if you want to set the layer to Ignore Raycast for all child objects. Select
Yes, change children so all the smaller prefab blocks making up Obstacles will be included in the
Ignore Raycast layer.
Save the scene and playtest. Again only the evil spheres disappear when the ray detects their
colliders. The difference now is that the game engine does not have to check every collider the ray
intersects, but literally ignores any colliders on the Ignore Raycast layer.
 
Search WWH ::




Custom Search