Unity Unity 3 — Questions and Answers
Question 1: Why is FixedUpdate() preferred over Update() for applying physics forces?
- It runs at a consistent physics timestep (Correct answer)
- It runs more often
- It ignores Time.deltaTime
- It only runs once
Correct answer: It runs at a consistent physics timestep
FixedUpdate() runs on a fixed timestep aligned with the physics engine, making force application consistent.
Question 2: What does the [SerializeField] attribute do?
- Hides a public field
- Exposes a private field in the Inspector (Correct answer)
- Serializes data to disk
- Marks a method as a coroutine
Correct answer: Exposes a private field in the Inspector
[SerializeField] allows a private field to appear and be edited in the Inspector while remaining private in code.
Question 3: Which collision callback fires when two colliders begin touching (both have colliders, one a non-trigger Rigidbody)?
- OnTriggerEnter
- OnCollisionEnter (Correct answer)
- OnMouseDown
- OnControllerColliderHit
Correct answer: OnCollisionEnter
OnCollisionEnter is called when two non-trigger colliders first make contact.
Question 4: What is required for OnTriggerEnter to fire?
- Both colliders must be solid
- At least one collider marked Is Trigger and a Rigidbody present (Correct answer)
- Two Rigidbodies with gravity
- A MeshCollider only
Correct answer: At least one collider marked Is Trigger and a Rigidbody present
Trigger events require one collider set to Is Trigger and a Rigidbody on at least one of the objects.
Question 5: What does a Coroutine allow you to do in Unity?
- Run code on a separate CPU thread
- Pause execution across frames using yield (Correct answer)
- Compile shaders
- Bake navigation meshes
Correct answer: Pause execution across frames using yield
A coroutine can suspend its execution and resume on a later frame using yield statements.
Question 6: Which yield instruction waits for a real-time delay?
- yield return null
- yield return new WaitForSeconds(t) (Correct answer)
- yield break
- yield return new WaitForEndOfFrame()
Correct answer: yield return new WaitForSeconds(t)
WaitForSeconds pauses the coroutine for a given number of scaled seconds.
Question 7: What is the role of the AddComponent method?
- Removes a script
- Attaches a component to a GameObject at runtime (Correct answer)
- Loads a scene
- Plays an animation
Correct answer: Attaches a component to a GameObject at runtime
GameObject.AddComponent adds a new component of the specified type to a GameObject during play.
Why is FixedUpdate() preferred over Update() for applying physics forces?