AI Command Lab // Flight Simulator
6E: Singleton Sanitation
Initial AI Output (Fragile)
// AI-Generated Code: Dangerous Duplication
void Awake() {
DontDestroyOnLoad(this);
// Audit Fail: If you return to the Main Menu and
// load the game again, a second GameManager is created.
}
Initial AI Prompt
"You ask the AI: "Create a GameManager that persists across scenes.""
Pilot Comm Link
Mission Objective: A skilled Mechanic directs the AI to use the Singleton Pattern. You command: "Implement the Singleton pattern to ensure only one instance exists."
Optimized Protocol
public static GameManager Instance;
void Awake() {
if (Instance == null) {
Instance = this;
DontDestroyOnLoad(gameObject);
} else {
Destroy(gameObject); // Throw the imposter overboard
}
}