using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class shoot : MonoBehaviour {
public Rigidbody bulletPrefab;
public Transform bulletSpawn;
public float shootingSpeed;
public int bulletAmmount;
int shootedBulletAmmount;
public int currentBulletAmmount;
bool isSpawned;
bool canShoot;
void Start()
{
canShoot = true;
}
void Update()
{
Shoot ();
Reload ();
}
void Shoot ()
{
if(canShoot==true)
{
if (Input.GetButtonDown ("Fire1")) {
shootedBulletAmmount = shootedBulletAmmount++;
isSpawned = true;
print (shootedBulletAmmount);
Rigidbody rocketInstance;
rocketInstance = Instantiate (bulletPrefab, bulletSpawn.position, bulletSpawn.rotation) as Rigidbody;
rocketInstance.AddForce (bulletSpawn.forward * shootingSpeed);
}
}
}
void Reload()
{
if(isSpawned==true)
{
currentBulletAmmount = bulletAmmount -= shootedBulletAmmount;
}
if (currentBulletAmmount <= 0)
{
canShoot = false;
}
if (canShoot == false)
{
StartCoroutine("readyShoot");
}
}
IEnumerator readyShoot()
{
yield return new WaitForSeconds (3);
canShoot = true;
bulletAmmount = 20;
shootedBulletAmmount = 0;
currentBulletAmmount = 0;
}
}