- Home /
Play an Animation through a Script
Hello,
I'm trying to get something to react to a metronome script I've been messing with. The Metronome script I have uses events and delegates to allow multiple objects to be connected to it. I created a script called a "Metronome Reciever." The script appears below:
public class MetronomeReciever : MonoBehaviour {
public Animation bopAnim = null;
public Metronome metronome = null;
void Start()
{
metronome.OnTick += OnTick;
metronome.OnNewMeasure += DoOnNewMeasure;
}
public void OnTick(Metronome m)
{
bopAnim.Play("Bop");
Debug.Log("Tick");
}
public void DoOnNewMeasure(Metronome m)
{
Debug.Log("New Measure");
}
}
I've been trying to get an animation to play with the "OnTick" function is triggered but I'm having problems with the animator. Using "bopAnim.Play("Bop"), for instance doesn't react the way I was expecting, with the animation only playing once at runtime when it should be playing on every tick.
Am I setting up my animator wrong or is there a specific way to reach animation states in the animator?
Answer by NeverEndingPrjct · Aug 25, 2014 at 02:50 PM
use an animator
this do all the crazy stuff for u ... u have only to set their atributes with .SetXxx
Your answer
Follow this Question
Related Questions
Score system using events to pass data? 1 Answer
Event to change level 1 Answer
custom event delegate - convertible error 3 Answers
What part of the delegate gets passed back?The return type? 1 Answer
Delegate an event 2 Answers