Gun Reloads now if empty

This commit is contained in:
pbg2h23akl
2024-07-01 16:37:19 +02:00
parent 6bb0bc1c39
commit df37d14120
3 changed files with 32 additions and 61 deletions

View File

@@ -7,17 +7,44 @@ public class WeaponScript : MonoBehaviour
public GameObject spawnpoint;
public GameObject bullet;
private void shoot(){
public DataBullet dataBullet;
private int ammo;
private bool isReloading = false;
private float time = 0;
public float reloadTime;
public void reload(){
if(ammo == 0){
isReloading = true;
}
if(isReloading){
time += Time.deltaTime;
if(time > reloadTime){
ammo = dataBullet.ammo;
time = 0;
isReloading = false;
}
}
}
public void shoot(){
if(ammo != 0){
if(Input.GetKeyDown(KeyCode.Mouse0)){
Instantiate(bullet,spawnpoint.transform.position,transform.rotation);
ammo--;
}
}else{
reload();
}
}
void Start()
{
dataBullet = GetComponentInChildren<DataBullet>();
ammo = dataBullet.ammo;
}
// Update is called once per frame