x


animation script help

Made a cannon and animated inside unity. it has a muzzle brake that moves backwards when fired. the animation works but i cant get the script to make it work in game play. I need to have it play the animation when the w key is pressed down once. here is the script i.m trying to use any help would be appreciated.

function Update()
{
 if(Input.GetKeyDown("w"))
 {
  // Plays the reload animation - stops all other animations
  animation.Play("reload", PlayMode.StopAll);
 }
}
more ▼

asked May 28 '12 at 11:52 PM

wayne57 gravatar image

wayne57
43 12 29 35

Looking at the code, one thought would be that the body of the if statment is not being executed. Place a "print" statement before the animation.play to see if it is being reached.

Personally, I would use the following:

if (Input.GetKeyDown(KeyCode.W)) ...

Also, when posting here, try and ensure that the format of the code is correct as it is difficult to read unformatted code.

May 29 '12 at 12:24 AM kolban
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Maybe something like this will work:

var Anima : AnimationClip;

function Update() {

    if(Input.GetKeyDown(KeyCode.W)) {

      animation.Play(Anima.name);   

    }
}

Based on the layers of your other animations this should play. If not, try adding this below the if statement

 animation[Anima.name].layer = 1; //adjust the number 1 higher if need be
more ▼

answered May 29 '12 at 12:04 PM

voncarp gravatar image

voncarp
82 2 4 7

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3768

asked: May 28 '12 at 11:52 PM

Seen: 239 times

Last Updated: May 29 '12 at 12:04 PM