Recall & Review
beginner
What does the
public keyword do in Unity scripts?It makes a variable accessible from other scripts and also visible and editable in the Unity Inspector.
Click to reveal answer
beginner
What is the purpose of the
[SerializeField] attribute in Unity?It makes a private variable visible and editable in the Unity Inspector without making it accessible from other scripts.
Click to reveal answer
intermediate
Why might you use
[SerializeField] instead of public for a variable?To keep the variable private (hidden from other scripts) but still editable in the Inspector, helping to protect your code from unwanted changes.
Click to reveal answer
beginner
Can a
private variable without [SerializeField] be edited in the Unity Inspector?No, private variables without
[SerializeField] are hidden from the Inspector and cannot be edited there.Click to reveal answer
beginner
What happens if you make a variable
public but do not use [SerializeField]?The variable is visible and editable in the Inspector and accessible from other scripts.
Click to reveal answer
Which keyword or attribute allows a private variable to be shown in the Unity Inspector?
✗ Incorrect
The [SerializeField] attribute makes private variables visible in the Inspector.
What does making a variable public in Unity do?
✗ Incorrect
Public variables are accessible from other scripts and visible in the Inspector.
Why use [SerializeField] on a private variable?
✗ Incorrect
[SerializeField] lets you edit private variables in the Inspector without exposing them to other scripts.
If a variable is private and has no [SerializeField], can you edit it in the Inspector?
✗ Incorrect
Private variables without [SerializeField] are hidden from the Inspector.
Which is a good reason to keep a variable private but serialized?
✗ Incorrect
Keeping variables private but serialized protects code while allowing easy editing in the Inspector.
Explain the difference between using
public and [SerializeField] for variables in Unity.Think about accessibility and Inspector visibility separately.
You got /4 concepts.
Why might a Unity developer prefer
[SerializeField] over making variables public?Consider code safety and ease of editing.
You got /3 concepts.