- Home /
Animations not working
Hey guys, I am working on a post apocalyptic zombie shooter I am right now trying to make the Animations play, I have looked at all tutorials on youtube and unity lessons, but they don't work, i have attached the animation to the gun but for some rason it dosent work, here is my script:
#pragma strict
var Bullet : Rigidbody;
var Spawn : Transform;
var Bullet_Speed : float = 1000;
function Start () {
}
function Update () {
if(Input.GetButtonDown("Fire1"))
{
Fire();
}
}
function Fire()
{
var Bullet1 : Rigidbody = Instantiate(Bullet, Spawn.position, Spawn.rotation);
Bullet1.AddForce(transform.forward * -Bullet_Speed);
audio.Play();
animation.Play(); // Animation not working here :(
}
Answer by screenname_taken · Dec 13, 2014 at 05:48 PM
Do you have a component on the object called Animation, or Animator? You are using the "animation" calls which are used for the old animation system, but if your object has an "Animator" component then that is for the new animation system. So you would be mixing the two systems. Check the actual unity tutorials on mechanim instead. http://unity3d.com/learn/tutorials/modules/beginner/animation
yes there is an animator component on the gun, unless you mean in the script also thx fr the info :)
Then your script is trying to access the "animation" component (old way of dealing with animations) while your component is the "animator", the new way of dealing with the animations.
animation.Play(); code is for the Old Animation component, not for the animator. If you are using an Animator, then you have to transition to states and assign the animation to a selected state. If you're using a legacy animation, check this answer http://answers.unity3d.com/questions/828207/problems-with-animation-4.html
Answer by wesleywh · Dec 15, 2014 at 05:26 PM
I would make sure that you can play the animation in the inspector. Also check if it is looping or not. If it isn't looping I know I have had some problems with my animations not playing before.
Answer by bleg cheese123 · Dec 18, 2014 at 07:11 PM
@wesleywh yeh, they play in the inspector alright but other then that it dosent work. :(
As i've said, you are mixing the two (incompatible) animation systems. You have the Animator component on your model (which is the new animation system) but you are trying to access it with the code for the old animation system (the legacy system). You should take a look at the unity tutorials about animation. NOT any generic 3rd party tutorial on youtube, unless you know for sure that they are covering the new animation system, $$anonymous$$ecanim. Just take a look at the link i provided in my answer above.
As screen_taken has said you are mixing the two animation systems. I have written some code to help someone else play their animations with the "Animator" component here:
http://answers.unity3d.com/questions/857058/make-animation-stop-when-ai-dosent-have-a-target.html
Here is the code if you were using an "Animation" component on your character:
animation.Play("walk");//this will play your "walk" animation.
Now the issue with this is that if the animation wasn't built for your specific character it will not play. You can't play animations that was built for a different character.
Here is the example of turning walk on with the "Animator" component:
SetFloat("speed", myspeed);//this checks your speed and in your animator state if your speed > 0.1f play the walk animation by going to "walk" State that has your walk animation on it.
With the "Animator" component you CAN play animations that were built for a different character.
Your answer
![](https://koobas.hobune.stream/wayback/20220613173951im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
stopping a Coroutine while it is running. 1 Answer
Unity Android Fire1 UI Button? 1 Answer
My gun shoots while I'm reloading 2 Answers