Tier 1 Series 7

7A: The Access Audit

Pilot Record
Student Profile
"You don't leave the internal wiring of a flight computer hanging out where anyone can pull on them. You enclose them in a protective shell. If your AI makes every variable **public**, you've created **State Fragility**. A skilled Engineer audits for **Private Encapsulation**."

The Concept: Public vs. Private

In C#, **Access Modifiers** define who can see and change your data. Public means anyone can change it; Private means only that specific script can touch it. In a professional workflow, we want our variables to be private by default to prevent accidental "Cross-Talk" from other scripts.

* **Private by Default:** If another script doesn't *need* to change it, keep it private.
* **[SerializeField]:** Use this attribute to keep a variable private while still allowing the Pilot to see/edit it in the Unity Inspector.
* **Properties:** If a variable must be read by others but only changed by itself, use a { get; private set; } property.
Red Flag Detected

The AI Trap: "The Naked Variable"

You ask the AI: "Track the drone's current fuel."

// 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; 
}

This is "Logic Exposure." It makes it impossible to track down *why* a variable changed because any of your 400,000 files could have touched it. A professional pilot demands a "Locked Cockpit" where data only changes through approved methods.

Elite Telemetry

Research shows "Elite" teams achieve 15% faster lead times by keeping AI on a "very tight leash."

  • Small Batches Solving one problem at a time prevents logic drift.
  • Modular Design Localizing the "blast radius" of AI changes.
  • Tight Loops Rapid iteration with constant code review.

The Mechanic's Correction

Corrective 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);
    }
}
Your Pilot Command
> 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."
Next Mission
The Camel Case Protocol