Why I want to use layer for? I know I can isolate GO (Game object) from the scene, but to do what? Why doing that?
From the docs:
Layers are most commonly used by Cameras to render only a part of the scene, and by Lights to illuminate only parts of the scene. But they can also used by raycasting to selectively ignore colliders.
Tags are similar to layers, in that you can use them to mark/group GameObjects. However, tags are "intended to identify GameObjects for scripting purposes," while layers are "used to define how Unity should render GameObjects in the Scene."
If you need to identify certain objects from your scripts (such as enemies, asteroids, walls, etc.), use Tags. If you need to control how certain GameObjects are rendered, use Layers.
Also, selective raycasting - as in only raycasting against colliders in specific layers as opposed to raycasting against all colliders.
Example:
void TestLineOfFire ()
{
LayerMask mask = 1 << LayerMask.NameToLayer ("Friendlies") |
1 << LayerMask.NameToLayer ("Enemies");
weapon.willHitSoftTarget = Physics.Raycast (
transform.position,
transform.forward,
weapon.maximumRange,
mask
);
}
For more information on masks and layer masks, check out the How do I use layermasks? question.
Gabriel, can you please explain a bit about selective raycasting? I can't find anything about it in the docs.