x


How do i make a character accelerate and play an animation when the click left-shift

I wanted to make a script that makes my character move faster when they click left-shift. i would also like it to play a certain animation. a few things to take into thought tho i dont want it to play the whole animation just until when they stop pressing left-shift. i already have the animation with the character. it would be nice if there was a variable for it so i can just drag the animation onto the varaible

more ▼

asked Aug 17 '10 at 06:24 AM

Brennan gravatar image

Brennan
62 14 16 21

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

1 answer: sort voted first

Search documentation - http://unity3d.com/support/documentation/ScriptReference/Animation.html Detect left mouse button - Input.GetKey("mouse 0") will detect a left-mouse buttom click and replace mouse 0 with left shift for left shift.

So full code:

function Update() {
   if (Input.GetKey("left shift")) { 
      animation.Play("nameOfAnimation", PlayMode.StopAll);
      transform.Translate(transform.forward * (normalSpeed * 2));
   }
}

The animation should be stored in the Animation component of the gameObject

more ▼

answered Dec 28 '10 at 07:49 PM

fireDude67 gravatar image

fireDude67
945 9 15 30

how do i stop animation when key is released

Nov 10 '12 at 06:19 PM Skyline Studios
(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:

x3791
x3460
x1044
x823
x27

asked: Aug 17 '10 at 06:24 AM

Seen: 1619 times

Last Updated: Nov 10 '12 at 06:19 PM