PBG2H23ABR_PBG2H23AKL_PMC_P.../Plunderblock/Assets/Scripts/ScriptsKevin/WeaponScript.cs
2024-07-05 11:07:17 +02:00

72 lines
1.8 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WeaponScript : MonoBehaviour
{
public ParticleSystem muzzle;
public GameObject spawnpoint;
public GameObject bullet;
public DataBullet dataBullet;
private int ammo;
private bool isReloading = false;
private float time = 0;
public float reloadTime;
private bool delayOver = true;
public float schussInterval;
private float delay = 0;
public void checkReload(){
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(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()
{
ammo = dataBullet.ammo;
muzzle = GetComponentInChildren<ParticleSystem>();
spawnpoint = GameObject.Find("Player/PlayerView/BulletSpawnpoint");
}
// Update is called once per frame
void Update()
{
checkDelay();
shoot();
checkReload();
}
}