The RequireComponent attribute lets automatically add required component as a dependency.
// Mark the PlayerScript as requiring a rigidbody in the game object. @script RequireComponent(Rigidbody)function FixedUpdate() { rigidbody.AddForce(Vector3.up); }
[RequireComponent (typeof (Rigidbody))] public class PlayerScript : MonoBehaviour { void FixedUpdate() { rigidbody.AddForce(Vector3.up); } }
RequireComponent | Require a single component. |
---|