连接的服务器的时候使用到Get很频繁,下面遍说一下怎么在Unity使用Get来获取数据
private IEnumerator GetReservoirData(string url)
{
UnityWebRequest www = UnityWebRequest.Get(url);
yield return www.SendWebRequest();
cacheContent = www.downloadHandler.text;
if (www.result == UnityWebRequest.Result.Success)
{
Debug.Log("接收服务器数据成功:"+cacheContent );
}
else
{
Debug.Log("接收服务器数据失败"+cacheContent);
}
yield return waitTime;
}
WaitForSeconds waitTime = new WaitForSeconds(1.0f);