Unity tutorial : loading 3d asset from external server in Unity3D

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");
    }
}


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);
        }
    }
}

** Vector3 pos = new Vector3(1, 2, 3); // as an example
     Instantiate(wheel, pos, 90); // or change rotation to whatever you want.


Thanks

Advertisemen

Disclaimer: Gambar, artikel ataupun video yang ada di web ini terkadang berasal dari berbagai sumber media lain. Hak Cipta sepenuhnya dipegang oleh sumber tersebut. Jika ada masalah terkait hal ini, Anda dapat menghubungi kami disini.

Tidak ada komentar:

Posting Komentar

© Copyright 2017 Tutorial Unity 3D