A tag is a label you assign to a GameObject to identify it easily in your scripts. For example, you can tag all enemies with "Enemy" to find them quickly.
Click to reveal answer
beginner
What is a layer in Unity?
A layer is a way to group GameObjects for rendering and physics purposes. Layers help control which objects interact or are visible to cameras.
Click to reveal answer
beginner
How do you check a GameObject's tag in a script?
You use gameObject.CompareTag("TagName") or check gameObject.tag == "TagName" to see if it has a specific tag.
Click to reveal answer
intermediate
Why use layers for physics collisions?
Layers let you control which objects collide by setting collision rules in the Physics settings. This improves performance and game logic.
Click to reveal answer
beginner
Can a GameObject have multiple tags or layers?
No, a GameObject can have only one tag and one layer at a time. But you can create custom tags and layers to organize your objects better.
Click to reveal answer
What is the main purpose of tags in Unity?
ATo control rendering order
BTo group objects for physics collisions
CTo identify GameObjects easily in scripts
DTo change object colors
✗ Incorrect
Tags help you identify and find GameObjects in your scripts quickly.
How many tags can a GameObject have at once?
ANone
BTwo
CMultiple
DOne
✗ Incorrect
A GameObject can have only one tag at a time.
What is a common use of layers in Unity?
ATo control which objects collide
BTo assign textures
CTo name GameObjects
DTo write scripts
✗ Incorrect
Layers help control physics collisions and rendering visibility.
Which method is recommended to check a GameObject's tag in code?
AgameObject.GetTag()
BgameObject.CompareTag("TagName")
CgameObject.HasTag("TagName")
DgameObject.CheckTag()
✗ Incorrect
CompareTag is the recommended and efficient way to check tags.
Can layers affect camera visibility?
AYes, cameras can cull layers
BNo, layers only affect physics
CNo, layers only affect tags
DYes, layers change object colors
✗ Incorrect
Cameras can be set to render or ignore specific layers.
Explain the difference between tags and layers in Unity and give an example of when to use each.
Think about how you find objects vs how you control collisions or visibility.
You got /4 concepts.
Describe how you would use layers to optimize physics collisions in a Unity game.
Consider how layers can prevent unnecessary collision checks.
You got /4 concepts.
Practice
(1/5)
1. What is the primary purpose of Tags in Unity?
easy
A. To identify and find GameObjects by name
B. To control the rendering order of objects
C. To group objects for physics collisions
D. To store numerical values for objects
Solution
Step 1: Understand what Tags do
Tags are used to label GameObjects with a name for easy identification.
Step 2: Compare with Layers
Layers group objects mainly for collision and rendering, not identification by name.
Final Answer:
To identify and find GameObjects by name -> Option A
Quick Check:
Tags = Identify objects by name [OK]
Hint: Tags name objects; layers group them for collisions [OK]
Common Mistakes:
Confusing tags with layers
Thinking tags control rendering
Assuming tags store numbers
2. Which of the following is the correct way to check if a GameObject has a specific tag in C# script?
easy
A. if (gameObject.CheckTag("Enemy"))
B. if (gameObject.tag == "Enemy")
C. if (gameObject.HasTag("Enemy"))
D. if (gameObject.layer == "Enemy")
Solution
Step 1: Recall Unity tag checking syntax
Unity uses gameObject.tag == "TagName" to check tags.
Step 2: Identify incorrect options
layer is an int, not string; HasTag and CheckTag are not Unity methods.
Final Answer:
if (gameObject.tag == "Enemy") -> Option B
Quick Check:
Check tag with .tag == "Name" [OK]
Hint: Use gameObject.tag == "TagName" to check tags [OK]
Common Mistakes:
Using layer property to check tags
Calling non-existent methods like HasTag
Comparing layer to string
3. Given this code snippet, what will be printed if the GameObject's layer is set to 8?
void Start() {
if (gameObject.layer == 8) {
Debug.Log("Layer is 8");
} else {
Debug.Log("Other layer");
}
}
medium
A. Layer is 8
B. Other layer
C. Compile error
D. No output
Solution
Step 1: Understand the layer property
The layer property is an integer representing the object's layer number.
Step 2: Check the condition
If the GameObject's layer is 8, the condition gameObject.layer == 8 is true, so it prints "Layer is 8".
Final Answer:
Layer is 8 -> Option A
Quick Check:
Layer 8 matches condition, prints "Layer is 8" [OK]
Hint: Layer is an int; compare with number, not string [OK]
D. Using assignment (=) instead of comparison (==) in if condition
Solution
Step 1: Identify the if condition error
The code uses = which assigns "Player" to gameObject.tag instead of comparing.
Step 2: Understand correct comparison
To compare, use == operator, so it should be gameObject.tag == "Player".
Final Answer:
Using assignment (=) instead of comparison (==) in if condition -> Option D
Quick Check:
Use == to compare tags, not = [OK]
Hint: Use == for comparison, not = assignment [OK]
Common Mistakes:
Using = instead of ==
Thinking Debug.Log can't be inside if
Believing tag is inaccessible in Update
5. You want to make sure your player GameObject only collides with enemies on a specific layer called "EnemyLayer". Which approach correctly uses layers to achieve this in Unity's physics settings?
hard
A. Assign all objects to Default layer and ignore collisions in script
B. Use tags to identify enemies and check collisions manually in code
C. Assign player to "PlayerLayer" and enemies to "EnemyLayer", then configure Layer Collision Matrix to allow collisions only between these layers
D. Set both player and enemies to the same layer and disable collisions globally
Solution
Step 1: Understand layer collision matrix
Unity's Layer Collision Matrix lets you control which layers collide with each other.
Step 2: Assign layers and configure collisions
Assign player and enemies to different layers and enable collision only between those layers in the matrix.
Step 3: Evaluate other options
Using tags for collision is inefficient; ignoring collisions or disabling globally is not selective.
Final Answer:
Assign player to "PlayerLayer" and enemies to "EnemyLayer", then configure Layer Collision Matrix to allow collisions only between these layers -> Option C
Quick Check:
Use layers + collision matrix for selective collisions [OK]
Hint: Use Layer Collision Matrix to control collisions by layers [OK]
Common Mistakes:
Using tags instead of layers for collision filtering
Assigning all objects to Default layer
Disabling collisions globally instead of selectively
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.