So i have this code that shoots bullets, but now i want to add a timer so the player can’t spam that much bullits.
public class Shooting : MonoBehaviour {
public float speed = 20f;
public Rigidbody projectile;
float timer = 0f;
void Update ()
{
if (Input.GetButton("Fire1"))
{
if (timer <= 1)
{
//Timer Ini
timer = 5;
//Shooting
Rigidbody clone;
clone = Instantiate(projectile, transform.position, transform.rotation) as Rigidbody;
clone.velocity = transform.TransformDirection(Vector3.forward * speed);
}
}
if (timer => 4)
{
timer =-1;
}
}
}
this is what i did, could anyone tell me how to correct this, or how to do it the right way, i’m pretty new ![]()
Thanks in advance!
Bram.
Thank you very much!
– Brum