- Home /
animated a model with a button in Unity with vuforia
I am working with unity and vuforia and what i am wanting to do is have the image target render my 3d model and a visual button. the model will be animated. I need the button to start a new animation for the 3d model when pressed but as soon as the animation finishes it needs to go back to the original animation. Please help me find the correct way to do this.
Answer by Spinnernicholas · Nov 29, 2013 at 07:44 AM
For full answer, goto forum HERE.
[OLD] Using the animation component, you can have the button event call animation.Play("animation name");.
When the animation is over, animation.isPlaying = false;.
void Update()
{
if(!animation.isPlaying)
{
animation.Play("default animation");
}
}
so at the end it will go back to original animation? and i want a different obj to control the animated model's animations
so at the end it will go back to original animation? and i want a different obj to control the animated model's animations
Add this script to the same gameobject that has the animation component. It will do nothing until you call PreviewAnimation("defaultAnim", "previewAnim");. it will then activate itself and play the desired animation once before returning it to the default animation and deactivating itself.
class PreviewAnimation:$$anonymous$$onoBehavior
{
string origionalAnimation;
Wrap$$anonymous$$ode wrap$$anonymous$$ode;
void Awake()
{
//disable script
enabled = false;
}
public void PreviewAnimation(string origionalAnimation, string animation)
{
//enable script
enabled = true;
//Save Animation Settings
this.origionalAnimation = origionalAnimation;
wrap$$anonymous$$ode = this.animation.wrap$$anonymous$$ode;
//Play animation once
this.animation.wrap$$anonymous$$ode = Wrap$$anonymous$$ode.Once;
this.animation.Play(animation);
}
void Update()
{
if(!animation.isPlaying)
{
//Restore Animation Settings
animation.wrap$$anonymous$$ode = wrap$$anonymous$$ode;
animation.Play(origionalAnimation);
//disable script
enabled = false;
}
}
}
I am getting this error The type or namespace name `String' could not be found. Are you missing a using directive or an assembly reference? for 3 locations