I am currently working on a Vuforia AR Project. I am working on a part where I have an assetbundle containing png textures. There are around 177 textures. I want to download them and make them play in a sequence on a plane. This is my code for the downloading and playing part:
public class TextureLoadScript : MonoBehaviour
{
Texture2D[] tex = new Texture2D[177];
Material GoMaterial;
int frameCounter = 0;
public TrackableBehaviour trackableBehaviour;
public string imageSequenceName="ImageSequenceName_";
public string FolderName="Resources/ImageSequence";
public int numOfFrames;
AssetBundle bundle;
bool playing;
bool isLoading;
void Awake()
{
this.GoMaterial = this.renderer.material;
}
// Use this for initialization
void Start ()
{
if (trackableBehaviour) {
trackableBehaviour.RegisterTrackableEventHandler (this);
}
tex[0] = (Texture2D)bundle.Load(FolderName+imageSequenceName+"00000",typeof(Texture2D));
}
// Update is called once per frame
void Update ()
{
if(isLoading)
{
StartCoroutine("Download");
}
if(playing)
{
StartCoroutine("Play",0.0588f);
GoMaterial.mainTexture = tex[frameCounter];
}
}
IEnumerator Download()
{
string url = "mteam@mobilesandbox.cloudapp.net/IntroScene_android_android.unity3d";
WWW download = WWW.LoadFromCacheOrDownload(url,1);
yield return download;
if(download.error!=null)
{
Debug.LogError(download.error);
}
bundle=download.assetBundle;
Debug.Log ("Bundle Loaded Successfully"+bundle.name);
isLoading = true;
}
IEnumerator Play(float delay)
{
yield return new WaitForSeconds(delay);
if(frameCounter<numOfFrames-1)
{
++frameCounter;
tex[frameCounter] = (Texture2D)bundle.Load(FolderName+imageSequenceName+frameCounter.ToString("D5"),typeof(Texture2D));
}
else
{
playing = false;
}
}
During runtime it shows object reference not set to the instance of an object. I can see I am close enough. But I am not able to proceed further. Kindly help me on this