お好みのスクリプト言語を選択すると、サンプルコードがその言語で表示されます。
Namespace: UnityEngine
Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.
Close自動でコンポーネントを追加する場合に使用する属性です。
この属性の付いたスクリプトを ゲームオブジェクトにアタッチすると、設定したコンポーネントも自動でアタッチされるようになります。 これはセットアップエラーを回避するのに役に立ちます。 例えばあるスクリプトが Rigidbody が同じゲームオブジェクトに常に追加されることが必要な場合があります。 RequireComponent を使用することでこれを自動的に実行し、セットアップで間違えることがなくなります。
// Mark the PlayerScript as requiring a rigidbody in the game object. @script RequireComponent(Rigidbody) function FixedUpdate() { rigidbody.AddForce(Vector3.up); }
C# サンプル:
[RequireComponent (typeof (Rigidbody))] public class PlayerScript : MonoBehaviour { void FixedUpdate() { rigidbody.AddForce(Vector3.up); } }
RequireComponent | 1つのコンポーネントを必要とします |