can any one help with this, i want to it to shoot every .5 seconds 3 times then recharge for 2 seconds
//shooting
//rounds = 2
//reloadTime = 2
//rechargeTime = 2
if (currantRounds > 0)//if i have rounds left
{
Debug.Log(currantRounds + " Rounds out of " + rounds);
if (Vector2.Distance(transform.position, player.position) < sightDisteance)//if i can see player
{
Debug.Log("Player in sight");
if (amReloaded == true)//if i am reloaded
{
Debug.Log("Shoot");
Instantiate(bullet, firePoint.transform.position, quaternion.identity);//spawn bullet
currantRounds -= 1;//takes 1 rounds away
amReloaded = false;//set reloaded to false
}
else
{
StartCoroutine(Reloading());//if i am not reloaded then reload
}
}
} else
{
StartCoroutine(Recharging());//if i have ran out of charges then recharge
}
IEnumerator Recharging()
{
yield return new WaitForSeconds(rechargeTime);//wait some time
currantRounds = rounds;//recharge the rounds
amReloaded = true;//i am reloaded
Debug.Log("Recharged");
}
IEnumerator Reloading()
{
Debug.Log("Reloaded");
yield return new WaitForSeconds(reloadTime);//wait some time
amReloaded = true;//i am reloaded
}