Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a basic GameObject in Unity.
Unity
GameObject [1] = new GameObject(); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a data type like 'int' instead of a variable name.
✗ Incorrect
The variable name player is used to store the new GameObject instance.
2fill in blank
mediumComplete the code to add a Rigidbody component to a GameObject.
Unity
Rigidbody rb = [1].AddComponent<Rigidbody>(); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'this' when not inside a MonoBehaviour class.
✗ Incorrect
The player GameObject is the one to which we add the Rigidbody component.
3fill in blank
hardFix the error in the Update method to move the GameObject forward.
Unity
void Update() {
transform.Translate(Vector3.[1] * Time.deltaTime);
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'up' or 'right' which move the object in other directions.
✗ Incorrect
Using Vector3.forward moves the object forward in the scene.
4fill in blank
hardFill both blanks to create a dictionary mapping GameObject names to their components.
Unity
Dictionary<string, [1]> components = new Dictionary<string, [2]>();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using GameObject as the value type instead of Component.
✗ Incorrect
The dictionary maps strings (names) to Component objects, so both blanks use 'Component'.
5fill in blank
hardFill all three blanks to filter and store active GameObjects with Rigidbody components.
Unity
var activeRigidbodies = [1].Where(go => go.[2] && go.GetComponent<[3]>() != null).ToList();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'transform' instead of 'Rigidbody' in GetComponent.
✗ Incorrect
We filter gameObjects that are activeSelf and have a Rigidbody component.