PBG2H23ABR_PBG2H23AKL_PMC_P.../Plunderblock/Assets/Scripts/ScriptsKevin/WeaponScript.cs
2024-07-02 18:23:10 +02:00

59 lines
1.2 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;
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)){
muzzle.gameObject.SetActive(true);
//muzzle.Play();
Instantiate(bullet,spawnpoint.transform.position,transform.rotation);
ammo--;
}
}else{
reload();
}
}
void Start()
{
ammo = dataBullet.ammo;
muzzle = spawnpoint.GetComponentInChildren<ParticleSystem>();
}
// Update is called once per frame
void Update()
{
shoot();
}
}