- Home /
How to play a animation and change the position of gun till the shift key remain pressed.
My question is simple I want to play animation and change the position of gun till the shift key remain pressed and when I leave the shift key the animation stop and then the gun come back to its original position. I am noob and I am learning c# intermediate. I hope u understand. I tried following code but it`s not working.enter code here
public float animSpeed = 10; // Transition speed between running and walking animations.
public AnimationClip run;
public Vector3 runningPos; // Weapon position when running.
public Vector3 runningRot; // Weapon rotation when running.
void Update () {
if (Input.GetKeyDown (KeyCode.RightShift)) {
weaponAnimations.Stop ();
isRunning = true;
transform.localRotation = Quaternion.Lerp(transform.localRotation, Quaternion.Euler(runningRot), animSpeed * Time.deltaTime);
transform.localPosition = Vector3.Lerp(transform.localPosition, runningPos, animSpeed * Time.deltaTime);
weaponAnimations.CrossFade (run.name);
}
}
Thnaksa in advance!
Answer by zero_null · Dec 27, 2017 at 12:25 PM
Use GetKey Instead of GetKeyDown to have a continuous input effect !
Your answer
Follow this Question
Related Questions
Animator SetTrigger inexplicably not firing 1 Answer
Playing an animation attached to another object via C# script? 0 Answers
Mecanim animation clip mask 1 Answer
How do I animate a character in unity with a humanoid skeleton? 0 Answers
Is there a new retargetting system for the animation in 5.5? 1 Answer