- Home /
 
               Question by 
               pommerose94 · Jan 08, 2020 at 09:33 AM · 
                keyboarddelayshoot  
              
 
              keybind problem
problem with shoot delay It was working very well but i start using mire keybinder and now my shoot delay is not working anymore
using System.Collections; using System.Collections.Generic; using UnityEngine; using MireInput;
public class playerController2 : MonoBehaviour { private mInput _mInput;
 private void Awake()
 {
     var database = Resources.Load<InputActionDatabase>("InputActionDatabase");
     _mInput = new mInput(database);
     new KeybindData(database).Load();
 }
 public float moveSpeed;
 public float jumpForce;
 
 
 private Rigidbody2D theRB;
 
 public Transform groundCheckPoint;
 public float groundCheckRadius;
 public LayerMask whatIsGround;
 
 public bool isGrounded;
 
 private Animator anim;
 
 public GameObject snowBall;
 public Transform throwPoint;
 
 
 public AudioSource throwSound;
 //add bool to see if the ball can be thrown (true at start)
 bool canThrow = true;
 //time between the throwing
 public float throwDelay;
 // Start is called before the first frame update
 void Start()
 {
   theRB = GetComponent<Rigidbody2D>();
 
     anim = GetComponent<Animator>();  
 }
 // Update is called once per frame
 void Update()
 {
    
     isGrounded = Physics2D.OverlapCircle(groundCheckPoint.position, groundCheckRadius, whatIsGround);
 
     if (_mInput.GetAction("Move Left"))
     {
 
         theRB.velocity = new Vector2(-moveSpeed, theRB.velocity.y);
     }
     else if (_mInput.GetAction("Move Right"))
     {
         theRB.velocity = new Vector2(moveSpeed, theRB.velocity.y);
     }
     else
     {
         theRB.velocity = new Vector2(0, theRB.velocity.y);
     }
 
      if ((_mInput.GetActionDown("Jump")) && isGrounded)
     {
         theRB.velocity = new Vector2(theRB.velocity.x, jumpForce);
     }
     //add an other check if the ball can be thrown
     if ((_mInput.GetActionDown("Throw Ball")) && canThrow)
     {
         GameObject ballClone = (GameObject)Instantiate(snowBall, throwPoint.position, throwPoint.rotation);
         ballClone.transform.localScale = transform.localScale;
         anim.SetTrigger("Throw");
throwSound.Play();
         //switch the bool to false to prevent the throw
         canThrow = false;
         //start the coroutine which can be paused
         StartCoroutine(WaitForThrowDelay());
     }
 
     if (theRB.velocity.x < 0)
     {
         transform.localScale = new Vector3(-1, 1, 1);
     }
     else if (theRB.velocity.x > 0)
     {
         transform.localScale = new Vector3(1, 1, 1);
     }
 
     anim.SetFloat("Speed", Mathf.Abs(theRB.velocity.x));
     anim.SetBool("Grounded", isGrounded);
 }
 
 //coroutine
 IEnumerator WaitForThrowDelay ()
 {
     //pause it for the delay time
     yield return new WaitForSeconds(throwDelay);
     //enable the throwing again
     canThrow = true; 
 }
}
               Comment
              
 
               
              Your answer
 
 
             Follow this Question
Related Questions
unbuffered keyboard input delay 2 Answers
Aim at Something with Delay 1 Answer
Shoot Bullet Delay Enemy 0 Answers
Shoot Delay in C# 1 Answer
C# Enemy shoot on timer 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                