x


Animation doesn't play

Hi Unity users.

I have 3 animations. The first animation is the Idle animation. The second animation is the Walk animation. The third animation is the Shoot animation.

Well, the Idle animation plays when the player doesn't move. The the Walk animation plays when the Player is walking. But now when i press my left mouse button, the Shoot animation needs to play till i release the mouse button. So i got this script to make it possible. But it's not working. The Shoot animation won't play by left click.

function Start ()
{
   animation.wrapMode = WrapMode.Loop;

   animation["Shoot"].wrapMode = WrapMode.Once;

   animation["Shoot"].layer = 1;

   animation.Stop();
}

function Update () {

   if (Mathf.Abs(Input.GetAxis("Vertical")) > 0.1)
      animation.CrossFade("Walk");
   else
      animation.CrossFade("Idle");

   if (Input.GetMouseButtonDown (0))
      animation.CrossFade("Shoot");
} 

Someone can help me please?

Thanks in advance. DonIlias "

more ▼

asked Jan 07 '12 at 03:00 PM

Donilias gravatar image

Donilias
16 13 15 17

GetMouseButtonDown only returns true the first frame of pressing the mouse button, thus making it only execute once.

Jan 07 '12 at 05:51 PM OrangeLightning
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

For animation.CrossFade("Shoot') in the last few statements there, you are using Input.GetMouseButtonDown.

So the animation is played only when the mouse 'click' is detected because GetMouseButtonDown checks for click . Instead use Input.GetMouseButton, it checks whether the button is 'held' down and the animation is played untill mouse button is released.

more ▼

answered Jan 07 '12 at 05:50 PM

vatsalAtFEI gravatar image

vatsalAtFEI
734 13 18 25

(comments are locked)
10|3000 characters needed characters left

i would make a new Java script like this:

function update () {
    if(Input.Getbuttonup("fire1"))
    animation.Play("Shoot");
}

instead of "shoot" you can put any other animation

more ▼

answered Jan 07 '12 at 05:55 PM

BigBlob gravatar image

BigBlob
325 36 62 66

(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
x329
x224

asked: Jan 07 '12 at 03:00 PM

Seen: 1698 times

Last Updated: Apr 07 '12 at 06:44 PM