Unity协程异步加载资源

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SyncGetResources : MonoBehaviour
{

    private GameObject go;
    ResourceRequest request;
    // Start is called before the first frame update
    void Start()
    {
        StartCoroutine(SyncGetRes());
    }

    IEnumerator SyncGetRes()
    {
        request =  Resources.LoadAsync("GO");
        yield return request;
        go = request.asset as GameObject;
        if(go!= null)
        {
            Instantiate(go);
            Debug.Log("加载完成");
        }
        else
        {
            Debug.Log("加载失败");
        }
    }

    // Update is called once per frame
    void Update()
    {
        //加载进度
        Debug.Log(request.progress);
    }
}

 

你可能感兴趣的:(unity,协程,异步加载,unity)