using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DelegateTest : MonoBehaviour
{
delegate void MyDelegate();
MyDelegate myDelegate;
private void Awake()
{
InstanceTset._instace.Test3();
}
// Start is called before the first frame update
void Start()
{
myDelegate += Test1;
myDelegate += Test2;
//myDelegate -= Test2;
myDelegate();
myDelegate = null;
}
// Update is called once per frame
void Update()
{
}
void Test1()
{
print("66666");
}
void Test2()
{
print("999");
}
}
委托
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class InstanceTset : MonoBehaviour
{
public static InstanceTset _instace;
private void Awake()
{
_instace = this;
}
public void Test3()
{
print("444");
}
}
单例模式