Tier 2
Series 105
105G: The Factory Exam
Capstone Exam
"The factory line is jammed. The spawned enemies are flooding the Hierarchy root, the game crashes with a NullReference on startup, and the bullets fly forever until the game runs out of memory. Identify the three critical failures."
Target Asset for Audit
FRAGILE_CODE_DETECTED
using UnityEngine;
public class Spawner : MonoBehaviour {
public GameObject enemyPrefab;
public GameObject bulletPrefab;
// Audit Requirement: Lesson 105E (Awake/Start)
// Error 1: Race Condition
// Using Start to setup variables that others might need immediately.
void Start() {
SetupStats();
}
void Update() {
if (Input.GetKeyDown(KeyCode.Space)) {
// Audit Requirement: Lesson 105C (Parenting)
// Error 2: Hierarchy Pollution
Instantiate(enemyPrefab, transform.position, Quaternion.identity);
}
if (Input.GetButton("Fire1")) {
// Audit Requirement: Lesson 105D (Recycler)
// Error 3: Memory Leak
Instantiate(bulletPrefab, transform.position, Quaternion.identity);
// No Destroy() call exists for the bullet.
}
}
}