AI Command Lab // Flight Simulator
7A: The Access Audit
Initial AI Output (Fragile)
// AI-Generated Code: Exposed and Dangerous
public class Drone : MonoBehaviour {
// Audit Fail: Any script in the game can now
// change the drone's fuel to -5,000 or 1,000,000!
public float fuel = 100f;
}
Initial AI Prompt
"You ask the AI: "Track the drone's current fuel.""
Pilot Comm Link
Mission Objective: A skilled Mechanic directs the AI to **Enforce Encapsulation**. You command: "Make the fuel variable private but visible in the inspector, and provide a public method to consume it safely."
Optimized Protocol
// Corrected: Protected and Professional.
public class Drone : MonoBehaviour {
// Audit Pass: Visible to the Pilot, but invisible to other scripts.
[SerializeField] private float fuel = 100f;
// Approved way to change data.
public void BurnFuel(float amount) {
fuel = Mathf.Max(0, fuel - amount);
}
}