单例 + 委托

类A:
public class a : MonoBehaviour
{
public delegate void do_A(int i);
public event do_A enter_do_A;
public static a _instance;

private void Awake()
{
    _instance = this;
}

void Update()
{
    if (Input.GetKeyDown(KeyCode.Space))
    {
        enter_do_A(5); 
    }
}

}

类B:
public class b : MonoBehaviour
{
void Start()
{
a._instance.enter_do_A += get_do_a; //注意不要加括号
}

void get_do_a(int i)
{
    print("begain do A" + i);
}

}

你可能感兴趣的:(单例 + 委托)