0
0
Unityframework~10 mins

Component communication 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 get a component of type Rigidbody attached to the same GameObject.

Unity
Rigidbody rb = GetComponent<[1]>();
Drag options to blanks, or click blank then click option'
ACollider
BTransform
CRigidbody
DCamera
Attempts:
3 left
💡 Hint
Common Mistakes
Using a component type that is not attached to the GameObject.
Confusing Rigidbody with Collider.
2fill in blank
medium

Complete the code to send a message to call the method named "Jump" on this GameObject's components.

Unity
gameObject.[1]("Jump");
Drag options to blanks, or click blank then click option'
AInvoke
BSendMessage
CBroadcastMessage
DStartCoroutine
Attempts:
3 left
💡 Hint
Common Mistakes
Using BroadcastMessage which sends to children too.
Using Invoke which requires a method name and delay.
3fill in blank
hard

Fix the error in accessing the "health" variable from another component called PlayerStats.

Unity
int currentHealth = GetComponent<PlayerStats>().[1];
Drag options to blanks, or click blank then click option'
Ahealth
BplayerHealth
CHP
DHealth
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect capitalization.
Using a variable name that does not exist in PlayerStats.
4fill in blank
hard

Fill both blanks to get the AudioSource component from a child GameObject and play the sound.

Unity
AudioSource audio = GetComponentInChildren<[1]>();
audio.[2]();
Drag options to blanks, or click blank then click option'
AAudioSource
BPlay
CStop
DCollider
Attempts:
3 left
💡 Hint
Common Mistakes
Using Stop() instead of Play().
Trying to get a Collider instead of AudioSource.
5fill in blank
hard

Fill all three blanks to find a component of type Light, check if it is enabled, and then disable it.

Unity
Light lightComp = GetComponent<[1]>();
if (lightComp.[2]) {
    lightComp.[3] = false;
}
Drag options to blanks, or click blank then click option'
ALight
Benabled
Dactive
Attempts:
3 left
💡 Hint
Common Mistakes
Using "active" instead of "enabled" property.
Using wrong component type.