- Home /
Animate object on mouse button press
how can I play an animation on a button press, and on release, play another one. eg. while right mouse button is down-play animation and then pause at the end of the animation, then on release of the mouse button, play another animation.
I need this for looking down a sight... if there is an easier way then say, but what I stated above is what i'm looking for. thanks
Answer by AliAzin · Aug 31, 2010 at 09:30 AM
You can write something like this:
function Update(){
if (Input.GetMouseButtonDown(0)){
animation.clip = clip1;
animation.Play(animation.clip)
}
if (Input.GetMouseButtonUp(0)){
animation.clip = clip2;
animation.Play(animation.clip)
}
}
I made it simpler by making it:
function Update(){ if (Input.Get$$anonymous$$ouseButtonDown(1)){ animation.CrossFade("sight"); //named the animation "sight" to look down the sight } if (Input.Get$$anonymous$$ouseButtonUp(1)){ animation.CrossFade("norm"); //named the animation "norm" to return the gun to normal } }
Your answer
Follow this Question
Related Questions
What am I doing wrong with this attack script? 2 Answers
Play each animation with button or text 0 Answers
Animation pause on button press? 1 Answer
Play a video on clicking on an object 1 Answer
Two Animations With One Button Press 1 Answer