Advertisemen
Loading 3d models in unity3d in runtime from external server or from internet.
Thanks for watching
Please don’t forget to subscribe for more tutorials.
CreateAssetBundles.cs
using UnityEngine;
using System.Collections;
using UnityEditor;
public class CreateAssetBundles : MonoBehaviour
{
[MenuItem ("Assets/Build AssetBundles")]
static void BuildAllAssetBundles ()
{
BuildPipeline.BuildAssetBundles ("Assets/AssetBundles");
}
}
using System.Collections;
using UnityEditor;
public class CreateAssetBundles : MonoBehaviour
{
[MenuItem ("Assets/Build AssetBundles")]
static void BuildAllAssetBundles ()
{
BuildPipeline.BuildAssetBundles ("Assets/AssetBundles");
}
}
loadAsset.cs
using UnityEngine;
using System.Collections;
using System;
public class loadAsset : MonoBehaviour {
// Use this for initialization
void Start ()
{
string url = "http://filmbuzzer.com/AssetBundles/wheel";
WWW www = new WWW(url);
StartCoroutine(WaitForReq(www));
}
IEnumerator WaitForReq(WWW www)
{
yield return www;
AssetBundle bundle = www.assetBundle;
if(www.error == null){
GameObject wheel = (GameObject)bundle.LoadAsset("wheel");
Instantiate(wheel); // **Change its position and rotation
}
else{
Debug.Log(www.error);
}
}
}
using System.Collections;
using System;
public class loadAsset : MonoBehaviour {
// Use this for initialization
void Start ()
{
string url = "http://filmbuzzer.com/AssetBundles/wheel";
WWW www = new WWW(url);
StartCoroutine(WaitForReq(www));
}
IEnumerator WaitForReq(WWW www)
{
yield return www;
AssetBundle bundle = www.assetBundle;
if(www.error == null){
GameObject wheel = (GameObject)bundle.LoadAsset("wheel");
Instantiate(wheel); // **Change its position and rotation
}
else{
Debug.Log(www.error);
}
}
}
** Vector3 pos = new Vector3(1, 2, 3); // as an example
Instantiate(wheel, pos, 90); // or change rotation to whatever you want.
Thanks
Advertisemen
Tidak ada komentar:
Posting Komentar