1,先创建一个delegate管理器,
public delegate void ProjectPhoneNumWebRequestDelegate();
public delegate void GetProjectPhoneNumInfo(string s);
public class DelegateManager
{
public static ProjectPhoneNumWebRequestDelegate projectPhoneNumWebRequestDelegate;
public static GetProjectPhoneNumInfo getProjectPhoneNumInfo;
}
2,创建发送网络请求的脚本
public class WebRequestManager : MonoBehaviour
{
// Start is called before the first frame update
void Awake()
{
//这里使用delegate传入参数(可以理解为指向一个方法)
DelegateManager.projectPhoneNumWebRequestDelegate += GetProjectPhoneNumRequest;
}
void GetProjectPhoneNumRequest()
{
StartCoroutine(ProjectPhoneNumRequest());
}
IEnumerator ProjectPhoneNumRequest()
{
UnityWebRequest projectPhoneNumRequest =
UnityWebRequest.Get("这里写你的接口地址");
yield return pro