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);
}
上一篇: Unity 求两个向量间夹角