2024-06-14 16:58:09 +02:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
public class WeaponScript : MonoBehaviour
|
|
|
|
{
|
2024-07-02 18:23:10 +02:00
|
|
|
public ParticleSystem muzzle;
|
2024-06-14 19:08:04 +02:00
|
|
|
public GameObject spawnpoint;
|
2024-06-14 16:58:09 +02:00
|
|
|
public GameObject bullet;
|
2024-07-01 16:37:19 +02:00
|
|
|
|
|
|
|
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){
|
2024-06-14 16:58:09 +02:00
|
|
|
if(Input.GetKeyDown(KeyCode.Mouse0)){
|
2024-07-02 18:23:10 +02:00
|
|
|
muzzle.gameObject.SetActive(true);
|
|
|
|
//muzzle.Play();
|
2024-06-14 19:08:04 +02:00
|
|
|
Instantiate(bullet,spawnpoint.transform.position,transform.rotation);
|
2024-07-01 16:37:19 +02:00
|
|
|
ammo--;
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
reload();
|
2024-06-14 16:58:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
void Start()
|
|
|
|
{
|
2024-07-01 16:37:19 +02:00
|
|
|
ammo = dataBullet.ammo;
|
2024-07-02 18:23:10 +02:00
|
|
|
muzzle = spawnpoint.GetComponentInChildren<ParticleSystem>();
|
2024-06-14 16:58:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
void Update()
|
|
|
|
{
|
|
|
|
|
|
|
|
shoot();
|
|
|
|
}
|
|
|
|
}
|