AI Command Lab // Flight Simulator
302C: The Drone Factory
Initial AI Output (Fragile)
// AI-Generated Code: Scattered Logic
void SpawnRed() {
var d = Instantiate(redPrefab);
d.color = Color.red;
d.ammo = 100;
}
void SpawnBlue() {
var d = Instantiate(bluePrefab);
d.color = Color.blue;
d.ammo = 50;
}
Initial AI Prompt
"You ask the AI: "Spawn a Red Drone and a Blue Drone.""
Pilot Comm Link
Mission Objective: A skilled Navigator directs the AI to use a Factory.
Optimized Protocol
// Corrected: Centralized Production
public class DroneFactory : MonoBehaviour {
public GameObject Create(DroneType type) {
GameObject drone = Instantiate(prefabs[type]);
// All setup logic happens HERE and ONLY here.
drone.GetComponent<IDrone>().Initialize();
return drone;
}
}