https://docs.unity3d.com/kr/530/ScriptReference/RequireComponent.html
RequireComponent를 추가하면 요구되는 components를 의존성으로 자동으로 추가해준다.
무려 setup 에러를 피할 수 있다!
예를들어 Rigidbody에 항상 같은 GameObject가 추가되어지게 할 수 있다!
using UnityEngine;
// PlayerScript는 Rigidbody component를 가지는 GameObject를 필요로 한다!!
[RequireComponent (typeof (Rigidbody))]
public class PlayerScript : MonoBehaviour {
Rigidbody rb;
void Start() {
rb = GetComponent<Rigidbody>();
}
void FixedUpdate() {
rb.AddForce(Vector3.up);
}
}