AI Command Lab // Flight Simulator
2F: Static Utilities
Initial AI Output (Fragile)
// AI-Generated Code (Logic Failure)
public class Enemy : MonoBehaviour {
public static int health = 100; // ERROR: Shared across ALL enemies!
public void TakeDamage(int amount) {
health -= amount;
}
}
Initial AI Prompt
"You ask the AI: "Create an enemy script where I can easily see the health of any enemy from my UI manager.""
Pilot Comm Link
Mission Objective: Implement an Object Pool to manage active and inactive instances.
Optimized Protocol
// Corrected Code (Proper Isolation)
public class Enemy : MonoBehaviour {
public int health = 100; // Unique to each enemy instance
}
// Static is reserved for logic that never changes
public static class CombatMath {
public static int CalculateCrit(int damage) => damage * 2;
}