0
0
Unityframework~10 mins

Adding and removing components 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 add a Rigidbody component to the GameObject.

Unity
gameObject.AddComponent<[1]>();
Drag options to blanks, or click blank then click option'
ARigidbody
BCollider
CTransform
DAnimator
Attempts:
3 left
💡 Hint
Common Mistakes
Using a component that does not exist or is unrelated to physics.
Trying to add Transform which is already present by default.
2fill in blank
medium

Complete the code to remove the BoxCollider component from the GameObject.

Unity
Destroy(gameObject.GetComponent<[1]>());
Drag options to blanks, or click blank then click option'
AAudioSource
BMeshRenderer
CRigidbody
DBoxCollider
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to destroy a component that is not attached.
Using Destroy on the GameObject instead of the component.
3fill in blank
hard

Fix the error in the code to add a Light component correctly.

Unity
var light = gameObject.[1]<Light>();
Drag options to blanks, or click blank then click option'
ARemoveComponent
BAddComponent
CDestroyComponent
DGetComponent
Attempts:
3 left
💡 Hint
Common Mistakes
Using GetComponent instead of AddComponent.
Trying to remove or destroy instead of adding.
4fill in blank
hard

Fill both blanks to add a SphereCollider and then remove it from the GameObject.

Unity
var collider = gameObject.[1]<SphereCollider>();
Destroy(gameObject.[2]<SphereCollider>());
Drag options to blanks, or click blank then click option'
AAddComponent
BRemoveComponent
CGetComponent
DDestroyComponent
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to remove the component before adding it.
Using RemoveComponent which does not exist.
5fill in blank
hard

Fill all three blanks to add a AudioSource, get it, and then destroy it.

Unity
var audio = gameObject.[1]<AudioSource>();
var getAudio = gameObject.[2]<AudioSource>();
Destroy([3]);
Drag options to blanks, or click blank then click option'
AAddComponent
BGetComponent
CgetAudio
Daudio
Attempts:
3 left
💡 Hint
Common Mistakes
Destroying the wrong variable.
Using RemoveComponent which is not a Unity method.