0
0
Unityframework~10 mins

Public vs SerializeField in Unity - Interactive Practice

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

Complete the code to make the variable visible in the Unity Inspector.

Unity
public class Player : MonoBehaviour {
    [1] int health = 100;
}
Drag options to blanks, or click blank then click option'
Aprivate
Bpublic
C[SerializeField]
Dprotected
Attempts:
3 left
💡 Hint
Common Mistakes
Using private without SerializeField hides the variable in the Inspector.
Using protected does not show the variable in the Inspector.
2fill in blank
medium

Complete the code to keep the variable private but still show it in the Unity Inspector.

Unity
public class Enemy : MonoBehaviour {
    [1] int damage = 50;
}
Drag options to blanks, or click blank then click option'
A[SerializeField]
Bpublic
Cprivate
Dprotected
Attempts:
3 left
💡 Hint
Common Mistakes
Using private alone hides the variable in the Inspector.
Using public exposes the variable but changes its access level.
3fill in blank
hard

Fix the error in the code to correctly serialize a private variable.

Unity
public class Weapon : MonoBehaviour {
    [1] int ammoCount = 30;
}
Drag options to blanks, or click blank then click option'
A[SerializeField]
BSerializeField
Cpublic
Dprivate SerializeField
Attempts:
3 left
💡 Hint
Common Mistakes
Writing SerializeField without brackets causes a syntax error.
Combining private and SerializeField without brackets is invalid.
4fill in blank
hard

Fill both blanks to declare a private variable visible in the Inspector and initialize it.

Unity
public class Shield : MonoBehaviour {
    [1] int [2] = 75;
}
Drag options to blanks, or click blank then click option'
A[SerializeField]
Bpublic
CshieldStrength
Dprivate
Attempts:
3 left
💡 Hint
Common Mistakes
Using public instead of SerializeField changes access level.
Using generic names like 'value' instead of descriptive names.
5fill in blank
hard

Fill all three blanks to declare a private serialized float variable with a default value.

Unity
public class SpeedBoost : MonoBehaviour {
    [1] float [2] = [3];
}
Drag options to blanks, or click blank then click option'
A[SerializeField]
BboostSpeed
C5.5f
Dpublic
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the 'f' suffix on float values causes errors.
Using public instead of SerializeField changes access level.