Shoot Script Reload Help

Hey I need help with reload. I want it so after you press the reload button (r) you can’t immediately shoot after that. I’d also like it so the amount of time after you press r till you can shoot again to be a variable. Now I don’t want you to give me a straight up script, I’d like if you could step by step teach me how to do this. Here shoot script,

var prefabBullet:Transform;
var shootForce:float;
var shots : int = 0;
var maxShots : int = 30;
var shootSound : AudioClip;
function Update()
{
    if(Input.GetMouseButtonUp(0) && shots < maxShots)
    {
        var instanceBullet = Instantiate(prefabBullet, transform.position, Quaternion.identity);
        instanceBullet.rigidbody.AddForce(transform.forward * shootForce);
        audio.PlayOneShot(shootSound);
        shots++;
    }
    else if (shots <= maxShots && Input.GetKeyDown(KeyCode.R))
    {
        shots = 0;
    }
}

1 Answer

1

when u press r (if shots equal 0), make another function for that. Then use yield WaitForSeconds ( ), then make shots equal maxShots.