So I've been developing Hololens applications with c# and unity and have come across this problem.
Setup that I currently have: GameObject prefab that once instantiated, automatically plays an animation. About two GameObjects get instantiated every second, with a maximum of about 60 staying in the scene before being deleted.
What I'm trying to do: On a button click, stop all the animations on each gameobject.
I've tried creating a script on the prefab using these methods but none have worked:
public void StopAnimation()
{
anim = gameObject.GetComponent<Animation>();
anim.Stop();
}
//also tried
public void StopAnimation()
{
gameObject.GetComponent<Animation>().Stop();
}
//and have even tried destroying the gameobject
public void StopAnimation(){
Destroy(gameObject);
}