Unity 6.3
0 онлайн 2 гостей 3 в системе
Вход

UnityWebRequest.timeout

Declaration

public int timeout;

Описание

Число секунд, после которых UnityWebRequest пытается прервать запрос, если ответ не получен.

Значение по умолчанию — 0, что означает, что тайм-аут не применяется и UnityWebRequest будет ждать, пока не будет получен ответ.

Когда ответ занимает больше времени, чем значение, указанное в timeout, UnityWebRequest.error возвращает сообщение Request timeout.

using UnityEngine;
using System.Collections;
using UnityEngine.Networking;

// Ask the website to deliver an image that is very large. // Set the download to take more than 60 seconds. This causes // the "request timeout" error message.

public class ExampleScript : MonoBehaviour { void Start() { StartCoroutine(GetText()); }

IEnumerator GetText() { using UnityWebRequest www = UnityWebRequest.Get("https://my-website.com/verylargeimage.jpg");

// Set the timeout to 60 seconds. // Abort the request if the image doesn't download within the specified timeout. www.timeout = 60; yield return www.SendWebRequest();

if (www.result != UnityWebRequest.Result.Success) { Debug.LogError(www.error); } else { Debug.Log("image arrived"); } } }