Shoot Delay added

This commit is contained in:
pbg2h23akl
2024-07-05 11:07:17 +02:00
parent 0c1f0a5d87
commit 1d2e0fa470
2 changed files with 28 additions and 12 deletions

View File

@@ -16,7 +16,10 @@ public class WeaponScript : MonoBehaviour
public float reloadTime;
public void reload(){
private bool delayOver = true;
public float schussInterval;
private float delay = 0;
public void checkReload(){
if(ammo == 0){
isReloading = true;
}
@@ -31,17 +34,25 @@ public class WeaponScript : MonoBehaviour
}
public void shoot(){
if(ammo != 0){
if(Input.GetKeyDown(KeyCode.Mouse0)){
muzzle.gameObject.SetActive(true);
//muzzle.Play();
Instantiate(bullet,spawnpoint.transform.position,spawnpoint.transform.rotation);
ammo--;
}
}else{
reload();
if(delayOver){
if(Input.GetKeyDown(KeyCode.Mouse0)){
muzzle.gameObject.SetActive(true);
//muzzle.Play();
Instantiate(bullet,spawnpoint.transform.position,spawnpoint.transform.rotation);
ammo--;
delay = 0;
delayOver = false;
}
}
}
}
public void checkDelay(){
if(!delayOver){
delay += Time.deltaTime;
if(delay > schussInterval){
delayOver = true;
}
}
}
void Start()
{
@@ -53,7 +64,8 @@ public class WeaponScript : MonoBehaviour
// Update is called once per frame
void Update()
{
checkDelay();
shoot();
checkReload();
}
}