- Home /
how to declare a animation var
Is it possible to declare an animation variable as follows? var gun_animation : animation
i would like to be able to declare it and be able to call it in a following function. Thanks!
Answer by farooqaaa · Mar 23, 2012 at 09:31 AM
Are you talking about Animation component or an AnimationClip?
To declare an Animation component you can use:
var animationComp : Animation;
// test use
animationComp.Play("walk");
If you already have an animation component instance and want to declare an AnimationClip then you can use:
var walkAnimation : AnimationClip;
// test use
animationComp.Play(walkAnimaton.name);
alright well the way i'm doing it is declaring a animation clip as follows: var reload_animation : AnimationClip;
then calling it in the following statment: function Reload () {
// Wait for reload time first - then add more bullets!
yield WaitForSeconds(reloadTime);
// We have a clip left reload
if (clips > 0)
{
animation.CrossFade(reload_animation);
clips--;
bulletsLeft = bulletsPerClip;
}
}
however no animation slot pops up in the inspector. An alternitive option would be to re-name the animation clip that i have for it so that i can call it. Its current name is Take 001, but my project has multiple animations named Take 001. the prob is i have no idea how to re-name an animation and i really would like this script for ease of use.
You forgot to make it public.
Use this:
public var reload_animation : AnimationClip;
By default JavaScript/UnityScript variables are public.
i get the error: $$anonymous$$ identifire: reload_animation. Also, i made it public but it still does not show up in the inspector. P.S. i'm writing this in java.
In order to play an animation from an AnimationClip you will have to use .name:
animation.CrossFade(reload_animation.name);
Answer by SterlingStudios · Jul 01, 2014 at 06:11 PM
Why do all that work when you could just use a string?
#pragma strict
var animationName : String = "";
var delayTime : float = 1;
function Update () {
Animate();
}
function Animate () {
yield WaitForSeconds(delayTime);
animation.Play("" + animationName);
}
Your answer
Follow this Question
Related Questions
Continuing movement after animaton on GetButtonUp 0 Answers
Make condition for opening a door (can only be opened when a lever has been activated before) 1 Answer
How do i fix fbx animation import problem from UU3D? 0 Answers
Problem with additive animations 0 Answers
How to get jump animation to play? 0 Answers