AI Command Lab // Flight Simulator
3A: The Magic Number Trap
Initial AI Output (Fragile)
// AI-Generated Code: Rigid and Unsafe
void OnCollisionEnter(Collision collision) {
// Audit Fail: What is 10.0f? Why is it here?
// How do we change it later without re-compiling?
health -= 10.0f;
}
Initial AI Prompt
"You ask the AI: "Make the ship take damage when it hits something.""
Pilot Comm Link
Mission Objective: Implement the Singleton pattern to ensure a unique global instance.
Optimized Protocol
// Corrected: The value is now labeled and tunable in the Inspector
[SerializeField] private float collisionDamage = 10.0f;
void OnCollisionEnter(Collision collision) {
health -= collisionDamage;
}