欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Unity 3D从网上加载的方法

程序员文章站 2022-03-26 16:02:26
...
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ResLoad : MonoBehaviour {
    IEnumerator Start()
    {
    //加载的网址	1是版本号
    	var www=WWW.LoadFromCacheOrDownload("网址",1);
    	yield return www;
    	//从网上加载assetBundle包
    	AssetBundle myLoadedAssetBundle=www.assetBundle;
    	//从assetBundle包里面加载player
    	GameObject prefab=myLoadedAssetBundle.loadAsset("player") as GameObject;
    	//实例化加载的物体到场景里面
    	Instantiate(prefab).transform.position=Vector3.zero;
    	myLoadedAssetBundle.Unload(true);
    }