AssetBundle : Can anybody tell what's wrong in my code
This is my code. What I need to do is call ReturningRequested Function to work from another script. When I access bundle in returningRequested and call it from start() it works.
When I call it from my script that has been assigned to an emptyobject in UI, it shows
NullReferenceException: Object reference not set to an instance of an object ServerDownloadManager.ReturningRequested () (at Assets/ServerDownloadManager.cs:41) SceneValues.InstantaniateLizardexamplewithanimationcontrols (Int32 storynumber) (at Assets/Scripts/SceneValues.cs:190) SceneValues.Start () (at Assets/Scripts/SceneValues.cs:65)
Please do guide me should I create a new instance and call it OR Should I find it with findobjectoftype. From ReturningRequested() I am planning to return bundle.loadasset() in the future.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ServerDownloadManager : MonoBehaviour {
public string bundleUrl;
static AssetBundle bundle;
// Use this for initialization
IEnumerator Start () {
WWW www = new WWW(bundleUrl);
yield return www;
if(www.error!= null){
throw new System.Exception("There is an error" + www.error);
}
bundle = www.assetBundle;
print(bundle.GetAllAssetNames()[0]+ "Asset Name1");
// Instantiate(bundle.LoadAsset("Lizard"));
// ReturningRequested("Hello");
}
public static void ReturningRequested(){
print(bundle.GetAllAssetNames()[0]+ "Asset Name2");
}
}