unity5.4以上www可以设置请求超时时间了

IEnumerator Test()
    {
        UnityWebRequest wr = new UnityWebRequest();
        wr.url = "www.baidu.com";
        wr.timeout = 2;//超时时间
        yield return wr.SendWebRequest();
        //获得文本
        string text = wr.downloadHandler.text;
        //获得字节数组
        byte[] datas = wr.downloadHandler.data;


        //图片获取方式
       UnityWebRequest texture =  UnityWebRequestTexture.GetTexture("img url");
        texture.timeout = 3;//超时时间
       yield return texture.SendWebRequest();
       Texture2D tex2D = DownloadHandlerTexture.GetContent(texture);


        //音频获取方式
       UnityWebRequest audio = UnityWebRequestMultimedia.GetAudioClip("url",AudioType.ACC);
        yield return audio.SendWebRequest();
       AudioClip ac =  DownloadHandlerAudioClip.GetContent(audio);


        //视频
       UnityWebRequest movie = UnityWebRequestMultimedia.GetMovieTexture("url");
         yield return movie.SendWebRequest();
       MovieTexture mt =  DownloadHandlerMovieTexture.GetContent(movie);


        //assstbundle
        AssetBundle ab = DownloadHandlerAssetBundle.GetContent(wr);
    }

你可能感兴趣的:(unity)