In my app I have requirement that I will be given a url and using this url I have to download a fbx model and then show it in the scene.
I am able to download the model from the url using the below code.
IEnumerator loadModel(string modelName)
{
if (!isDownloaded)
{
string targetUrl = "http://XXX.XXX.X.XX:3000/" + modelName;
Debug.Log("targetUrl" + targetUrl);
WWW www = new WWW(targetUrl);
yield return www;
if (www.isDone)
{
Debug.Log("downloaded " + www.bytesDownloaded);
var path = System.IO.Path.Combine(Application.dataPath+"/Resources", modelName);
System.IO.File.WriteAllBytes(path, www.bytes);
isDownloaded = true;
LoadAndAttachModel(imageTargetTransform, modelName);
}
else
{
Debug.Log(www.bytesDownloaded);
}
}
}
And with the below code I tried using loading the model in the scene
public void LoadAndAttachModel(Transform parent, String modelName)
{
Debug.Log(modelName);
var path = System.IO.Path.Combine(Application.dataPath + "/Resources", modelName);
String name = modelName.Substring(0, modelName.IndexOf("."));
GameObject load = Resources.Load(modelName) as GameObject;
Debug.Log(load.name);
if (load != null)
{
// load.transform.parent = parent;
load.transform.localPosition = Vector3.zero;
load.transform.localRotation = Quaternion.Euler(new Vector3(90, 90, 0));
load.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
}
else
{
Debug.LogWarning("Can't find boneName : " + parent);
}
}
but this code always gives exception that the gameobject load is null. I tried with the obj model and that was working fine but with fbx models this is giving exception every time.
So how can I instantiate the downloaded gameobject in my scene ?