i want to display a mesh sequence so i imported my obj files and found a script and partially edit it a bit.My project looks like this:
the script is this:
using UnityEngine; using System.Collections;
/** * Animate a mesh by cycling through different meshes. * @author bummzack */ public class MeshAnimation : MonoBehaviour {
public Mesh[] Meshes;
public bool Loop;
public float FrameDuration;
private int _index;
private bool _playing = true;
private float _accumulator;
private MeshFilter _meshFilter;
public void Start()
{
_meshFilter = GetComponent<MeshFilter>();
_index = 0;
}
public void Update()
{
_accumulator += Time.deltaTime;
if(_accumulator >= FrameDuration){
_accumulator -= FrameDuration;
_index = (_index + 1) % Meshes.Length;
if(_index == 0 && !Loop){
Stop();
return;
}
_meshFilter.mesh = Meshes [_index];
print ("Hello World");
}
}
}
the line that causes the problem is this:
_meshFilter.mesh = Meshes[_index];
and the problem shown in the console is this:
NullReferenceException MeshAnimation.Update () (at Assets/MeshAnimation.cs:43)
i know it has something to do with Meshes[_index} being null but i cant find the solution because i think the Meshes array is properly filled.Can anyone suggest a solution? Thank you all in advance.