Tier 1
Series 1
1B: Scope Authority
"In a commercial airliner, the passengers don't need access to the engine cutoff switch. Only the pilot does. If you give everyone access to every button, a simple mistake by a passenger could bring down the whole plane."
The Concept: Public vs. Private
As we discuss in Chapter 1, variables have "Scope." This determines which other parts of your game can see or change that data.
public: Visible to every other script in the game. Use sparingly for "Shared" data.
private: Hidden from other scripts. This is the "Safe Default" for internal logic.
public: Visible to every other script in the game. Use sparingly for "Shared" data.
private: Hidden from other scripts. This is the "Safe Default" for internal logic.
Red Flag Detected
The AI Trap: "The Open Cockpit"
You ask the AI: "Make a script that manages the player's internal movement speed."
// AI-Generated Code
public float moveSpeed = 5.0f; // Anyone can change this!
void Update() {
// Movement logic...
}
If moveSpeed is public, a UI script or an Enemy script could accidentally change the player's speed. Your internal "engine data" should be protected.
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 Pilot's Correction
Corrective Protocol
// Corrected Pilot Code [SerializeField] private float moveSpeed = 5.0f; // Now it is visible in the Unity Inspector, // but PROTECTED from other scripts.
Your Pilot Command
> A professional Pilot uses tags for comparison rather than string equals.