반응형




"Tag"and "Layer"

there are two parameters in the window of inspector named "Tag" and "Layer".can anybody tell me what is their the meaning

2 Replies

avatar image
5

Answer by Mike 3 

Tags are used for finding objects with a specific tag ( e.g. FindWithTag(str) ).

Layers are used for determining which objects are raycast to, which get renderered, lit, and which objects collide together

Check the manual for more info:

http://unity3d.com/support/documentation/Components/Layers.html

http://unity3d.com/support/documentation/Components/Tags.html

avatar image
1

Answer by blueLED 

Layers can be used to identify objects at a high level. Some examples would be:

  • level collision

  • pick up item

  • water

  • enemy

So when your code is checking for where the player can walk, you would only check for objects in the "level collision" layer and ignore the rest. If you didn't want the player to collide against something, say, a hologram, then you wouldn't set its layer to "level collision" and the player could pass right through it.

Tags could then be used to define the object at a finer level, for example, if the object is set to the "level collision" layer, its tag could then be set to:

  • dirt

  • metal

  • wood

So your code can use the tag to determine which sound effect to play when the player walks over or touches the object. Or it could be used to determine what kind of bullet mark should be left on the surface if you shoot it.

Another use for layers is to decide which objects get lit by which lights. For example, make a layer called "RedLightObjects". Then make a red light and set its culling mask to "RedLightObjects". Now, the red light will only light up those objects in the scene set to that layer and ignore the rest. Tags would not be efficient for this purpose.



http://answers.unity3d.com/questions/31892/tagand-layer.html



반응형

+ Recent posts