Unity

[Attribute] RequireComponent

JiHxxn 2024. 3. 16. 15:28

📜 information

  1. RequireComponent 란 요구되는 컴포넌트를 종속성으로 자동으로 추가해준다.
[RequireComponent(typeof(Rigidbody))]
public class RequireTest : MonoBehaviour
{}
        2. 자동으로 추가된 컴포넌트를 삭제 하려할 시 경고창을 띄움.


📖 참고 문서

Unity - Scripting API: RequireComponent

 

Unity - Scripting API: RequireComponent

When you add a script which uses RequireComponent to a GameObject, the required component is automatically added to the GameObject. This is useful to avoid setup errors. For example a script might require that a Rigidbody is always added to the same GameOb

docs.unity3d.com