Layers And Tags Flashcards
Uses of layers
You can use layers to optimize your project and work flow. Common uses of layers include
Layer based rendering and layer based collision
Camera and culling mask with layers
You can render only the objects in a particular layer, or selection of layers, if you use the Cameras culling mask. To change the culling mask, select the camera you want to use, and select the Culling Mask dropdown in the inspector window.
If you clear the checkbox of a layer, it doesn’t render in the scene.
Ui elements and screen space canvas children are exceptions to the culling mask check box, which prevents rendering, and render regardless
True
Ray cast with Layers
You can use layers to specify which GameObjects that a ray cast can intersect with.
To make a ray cast ignore a GameObject, you can assign it to the Ignore Raycast layer, or pass a LayerMask to the Ray cast API call
Physics.Raycast function
Physics.Raycast function uses a bit ask, and each but determines if a layer is ignored by rays or not. If all bits in the LayerMask are on, the Ray collides against all collides. If the LayerMask =0, there are no collisions
Example of a ray on layer 8
Int layerMask = 1 << 8; //Does the Ray intersect any objects which are in layer 8? If (Physics.Raycast (transform.position, Verctor3.forward, Mathf.Infinity, layerMask)) {Debug.Log("The ray hit the player")}
Ray cast with layers
You can do the inverse, so that the Ray collides with all layers except layer 8
If you don’t pass a LayerMask to the Raycast function, it still ignores colliders that use the IgnoreRaycast layer
What are tags in unity
Tags and layers must be declared in the tags and layers manager before using them
Tags are used to help identify game objects in unity
Tags in unity
A reference word that can be assigned to a GameObject
You can use the CompareTag(“ “) component to search for and affect on objects with the specific tags on them
You should not set a tag from the Awake or OnValidate method
You can set a tag to a GameObject by Void Start() {GameObject.tag = "Player" ; }