728x90
반응형
using UnityEngine;
public class EventManager :MonoBehaviour
{
public static EventManager instance;
public delegate void MyDelegate();
public event MyDelegate eventCall;
void Awake()
{
instance = this;
}
public void EventCall()
{
eventCall();
}
}
using UnityEngine;
public class Delegate_Sample : MonoBehaviour
{
void EventFunction()
{
Debug.Log("Success");
}
public void OnButtonClick()
{
Debug.Log("Click");
EventManager.instance.EventCall();
}
private void OnEnable()
{
EventManager.instance.eventCall += EventFunction;
}
private void OnDisable()
{
EventManager.instance.eventCall -= EventFunction;
}
}
728x90
반응형
'Unity' 카테고리의 다른 글
[Unity]Get or set accessor expected 오류 원인 및 해결방법 (0) | 2020.09.11 |
---|---|
[UNITY] SerializedObjectNotCreatableException: Object at index 0 is null 뜰 때 Inspector (0) | 2020.09.01 |
[Unity]AssetBundle Build샘플 스크립트 공유(Window/Android) (0) | 2020.08.31 |
[Unity] Unity Hub - JDK 설치 안될 때 (0) | 2020.08.27 |
[Unity] Android Permission 요청하기 (0) | 2020.08.19 |