- Home /
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
Answer by fireDude67 · Dec 28, 2010 at 07:49 PM
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
Your answer
Follow this Question
Related Questions
How can I tell Unity to wait to do something until after and animation has finished playing? 0 Answers
How can I tell Unity to wait to do something until after and animation has finished playing? 1 Answer
Javascript Movement Script. Why am I getting these errors? 2 Answers
Rewind/Play animations on demand. 1 Answer