0
0
Unityframework~10 mins

Variables and serialization 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 declare a public integer variable named score.

Unity
public class GameStats : MonoBehaviour {
    public [1] score;
}
Drag options to blanks, or click blank then click option'
Aint
Bstring
Cfloat
Dbool
Attempts:
3 left
💡 Hint
Common Mistakes
Using string instead of int for numbers.
Forgetting to specify the variable type.
2fill in blank
medium

Complete the code to make the variable health visible and editable in the Unity Inspector.

Unity
public class Player : MonoBehaviour {
    [[1]]
    private int health = 100;
}
Drag options to blanks, or click blank then click option'
ASerializeField
BHideInInspector
CNonSerialized
DObsolete
Attempts:
3 left
💡 Hint
Common Mistakes
Using HideInInspector hides the variable instead of showing it.
Using NonSerialized prevents serialization.
3fill in blank
hard

Fix the error in the code to correctly serialize a Vector3 position variable.

Unity
public class Enemy : MonoBehaviour {
    [SerializeField]
    private [1] position;
}
Drag options to blanks, or click blank then click option'
AVector2
BQuaternion
CVector4
DVector3
Attempts:
3 left
💡 Hint
Common Mistakes
Using Vector2 which only has two coordinates.
Using Quaternion which is for rotations.
4fill in blank
hard

Fill both blanks to declare a public string variable named playerName and initialize it to "Guest".

Unity
public class User : MonoBehaviour {
    public [1] playerName = [2];
}
Drag options to blanks, or click blank then click option'
Astring
B"Guest"
Cint
DGuest
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around the text value.
Using int instead of string for text.
5fill in blank
hard

Fill all three blanks to serialize a private float speed variable with initial value 5.5f.

Unity
public class Vehicle : MonoBehaviour {
    [[1]]
    private [2] speed = [3];
}
Drag options to blanks, or click blank then click option'
ASerializeField
Bfloat
C5.5f
Dint
Attempts:
3 left
💡 Hint
Common Mistakes
Using int instead of float for decimal numbers.
Forgetting the 'f' suffix on the number.