How to draw weapon using the same button or key?
Hi, everyone! Can I ask for a JS code or something to draw the weapon using the same button or key?
I already made two animations such as drawing the weapon to drawing it back. But I don't know what to code. Let's say I click "t" to draw the weapon and "t" again to draw it back.
Answer by hexagonius · Sep 12, 2015 at 09:08 PM
These might get you on the way:
bool weaponHolstered = true;
Animator animator;
void Start(){
animator = GetComponent.(Animator);
}
void Update(){
if(Input.GetButtonDown("t"){
if(weaponHolstered = !weaponHolstered)
animator.SetBool("draw",true);
else animator.SetBool("draw",false);
}
}
I haven't tested it, wrote it on my mobile phone. And I'm C#, so apologies if there's bugs. But if you put this in a script I a Gameobject with Animator and have setup the two animations so they transition to each other on the value of a draw bool, should work.
Thanks for the code. I'll try this. I'll notify you if there's a problem.
Your answer
Follow this Question
Related Questions
Weapons holding 0 Answers
Animation keeps playing even on wrapmode once 0 Answers
dual wielding sword Draw animation help 0 Answers