Answers for "unity everytime character shoot he has a short cooldown"

C#
0

unity everytime character shoot he has a short cooldown

#pragma strict
 
 //The interval you want your player to be able to fire.
 var FireRate : float = 1.0;
 
 //The actual time the player will be able to fire.
 private var NextFire : float;
 
 function Update () {
     //If the player is pressing fire AND The current time is > than when I want them to fire
     if(Input.GetButton("Fire1") && Time.time > NextFire)
     {        
             //If the player fired, reset the NextFire time to a new point in the future.
             NextFire = Time.time + FireRate;
             
             
             //Weapon firing logic goes here.
             
             
             Debug.Log("Firing once every 1s");
     }
 
 
 }
Posted by: Guest on May-10-2020

Code answers related to "unity everytime character shoot he has a short cooldown"

C# Answers by Framework

Browse Popular Code Answers by Language