Tier 2
Series 101
101A: The Inspector Audit
"A cockpit with unlabeled switches is a death trap. If a variable controls the engine power, it must be protected from accidental bumps by the passenger (other scripts) but visible to the pilot (the Inspector). If your AI makes everything 'public', you have created an unsafe flight environment."
The Concept: The [SerializeField] Attribute
Encapsulation is the practice of hiding data that shouldn't be touched. However, Unity developers often break this rule just to see variables in the Inspector.
* **Public:** Accessible by EVERY script. Dangerous for internal state.
* **Private:** Hidden from everyone, including the Inspector.
* **[SerializeField] private:** The "Sweet Spot." Hidden from other scripts (Safe) but visible in the Inspector (Tunable).
* **Public:** Accessible by EVERY script. Dangerous for internal state.
* **Private:** Hidden from everyone, including the Inspector.
* **[SerializeField] private:** The "Sweet Spot." Hidden from other scripts (Safe) but visible in the Inspector (Tunable).
Red Flag Detected
The AI Trap: "The Public Exposure"
You ask the AI: "Make the player's jump force adjustable in the Inspector."
// AI-Generated Code: Exposed and Dangerous
public class PlayerJump : MonoBehaviour {
// Audit Fail: Other scripts can accidentally change this!
public float jumpForce = 10f;
}
This is "State Fragility." If an enemy script accidentally does `player.jumpForce = 0;`, your player is grounded forever, and you will have no idea which script caused the error.
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 Tunable
public class PlayerJump : MonoBehaviour {
// Audit Pass: Only this script can change it via code,
// but the Designer can tune it in Unity.
[SerializeField] private float jumpForce = 10f;
}
Your Pilot Command
> Use the Input System Package to handle player actions rather than the old Input Manager.