0
0
Unityframework~10 mins

Tags and layers in Unity - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to assign the tag "Player" to a GameObject.

Unity
gameObject.tag = "[1]";
Drag options to blanks, or click blank then click option'
APlayer
BMainCamera
CUntagged
DEnemy
Attempts:
3 left
💡 Hint
Common Mistakes
Using a tag name that does not exist in the project.
Forgetting to use quotes around the tag name.
2fill in blank
medium

Complete the code to check if a GameObject has the tag "Enemy".

Unity
if (gameObject.[1]("Enemy")) {
    // Do something
}
Drag options to blanks, or click blank then click option'
AIsTag
BHasTag
CCheckTag
DCompareTag
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method that does not exist like HasTag or CheckTag.
Comparing tags with == operator instead of CompareTag.
3fill in blank
hard

Fix the error in the code to get the layer number of a GameObject.

Unity
int layerNumber = gameObject.[1];
Drag options to blanks, or click blank then click option'
Alayer
BLayerName
CGetLayer()
DLayer
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method instead of a property.
Using incorrect capitalization.
4fill in blank
hard

Fill both blanks to set a GameObject's layer to the layer number of the "UI" layer.

Unity
int uiLayer = LayerMask.[1]("UI");
gameObject.[2] = uiLayer;
Drag options to blanks, or click blank then click option'
ANameToLayer
Blayer
CLayer
DGetLayer
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect method names like GetLayer.
Trying to assign to a method instead of the layer property.
5fill in blank
hard

Fill all three blanks to create a LayerMask for the "Enemy" layer and check if a GameObject's layer is included.

Unity
LayerMask enemyMask = 1 << LayerMask.[1]("Enemy");
if ((enemyMask.value & (1 << gameObject.[2])) [3] 0) {
    // GameObject is on Enemy layer
}
Drag options to blanks, or click blank then click option'
ANameToLayer
Blayer
C!=
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '!=' in the condition.
Not shifting 1 by the layer number.
Using incorrect method names.