PBG2H23ABR_PBG2H23AKL_PMC_P.../Plunderblock/Assets/Scripts/ScriptsKevin/WeaponScript.cs
2024-07-01 16:37:19 +02:00

57 lines
1.1 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WeaponScript : MonoBehaviour
{
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)){
Instantiate(bullet,spawnpoint.transform.position,transform.rotation);
ammo--;
}
}else{
reload();
}
}
void Start()
{
dataBullet = GetComponentInChildren<DataBullet>();
ammo = dataBullet.ammo;
}
// Update is called once per frame
void Update()
{
shoot();
}
}