Need to press key 2 times to shoot
I have made a JavaScript for shooting, but i want to check if the animaton is playing before shooting so i made this:
#pragma strict
var arrowCasing : Rigidbody2D;
var ejectSpeed : int = 15;
var anim : Animator;
function Start () {
}
function Update () {
if(Input.GetKeyDown(KeyCode.Space)){
var arrow : Rigidbody2D;
anim.SetBool("Shooting", true);
if(anim.GetCurrentAnimatorStateInfo(0).IsName("Shoot")){
arrow = Instantiate(arrowCasing, transform.position, transform.rotation);
arrow.velocity = transform.TransformDirection(Vector2.right * ejectSpeed);
Wait(0.5);
}
}
}
function Wait(time : float)
{
yield new WaitForSeconds(time);
anim.SetBool("Shooting", false);
}
When i press space the animation is playing but i need press space a second time to shoot. How can I making the player shoot by pressing space once and be sure that the animation is playing ?
Comment
Your answer
Follow this Question
Related Questions
how to make enemy shoot one only time !! 2 Answers
2D collider is not working on instantiated gameobjects. 0 Answers
I need help making a UI button that when pressed shoots a projectile. 0 Answers
The bullet hole colliding with player and "Triggers" 0 Answers
Best way to animate a shooting-arm on my ball (Player)? 0 Answers