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;
|
2024-07-09 13:37:35 +02:00
|
|
|
public UI_Manager uI_Manager;
|
2024-07-01 16:37:19 +02:00
|
|
|
|
|
|
|
private int ammo;
|
|
|
|
private bool isReloading = false;
|
|
|
|
private float time = 0;
|
|
|
|
|
|
|
|
public float reloadTime;
|
|
|
|
|
2024-07-05 11:07:17 +02:00
|
|
|
private bool delayOver = true;
|
|
|
|
public float schussInterval;
|
|
|
|
private float delay = 0;
|
|
|
|
public void checkReload(){
|
2024-07-01 16:37:19 +02:00
|
|
|
if(ammo == 0){
|
|
|
|
isReloading = true;
|
|
|
|
}
|
|
|
|
if(isReloading){
|
|
|
|
time += Time.deltaTime;
|
|
|
|
if(time > reloadTime){
|
|
|
|
ammo = dataBullet.ammo;
|
2024-07-09 13:37:35 +02:00
|
|
|
uI_Manager.ammoReset();
|
2024-07-01 16:37:19 +02:00
|
|
|
time = 0;
|
|
|
|
isReloading = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public void shoot(){
|
2024-07-09 13:37:35 +02:00
|
|
|
if(ammo != 0 && delayOver){
|
|
|
|
if(Input.GetKeyDown(KeyCode.Mouse0)){
|
2024-07-05 11:07:17 +02:00
|
|
|
muzzle.gameObject.SetActive(true);
|
|
|
|
//muzzle.Play();
|
|
|
|
Instantiate(bullet,spawnpoint.transform.position,spawnpoint.transform.rotation);
|
|
|
|
ammo--;
|
2024-07-09 13:37:35 +02:00
|
|
|
uI_Manager.ammoDown();
|
2024-07-05 11:07:17 +02:00
|
|
|
delay = 0;
|
|
|
|
delayOver = false;
|
2024-07-09 13:37:35 +02:00
|
|
|
}
|
2024-07-05 11:07:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
public void checkDelay(){
|
|
|
|
if(!delayOver){
|
|
|
|
delay += Time.deltaTime;
|
|
|
|
if(delay > schussInterval){
|
|
|
|
delayOver = true;
|
|
|
|
}
|
2024-06-14 16:58:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
void Start()
|
|
|
|
{
|
2024-07-01 16:37:19 +02:00
|
|
|
ammo = dataBullet.ammo;
|
2024-07-03 13:56:17 +02:00
|
|
|
muzzle = GetComponentInChildren<ParticleSystem>();
|
|
|
|
spawnpoint = GameObject.Find("Player/PlayerView/BulletSpawnpoint");
|
2024-07-09 13:37:35 +02:00
|
|
|
uI_Manager = GameObject.FindGameObjectWithTag("Manager").GetComponent<UI_Manager>();
|
2024-06-14 16:58:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
void Update()
|
|
|
|
{
|
2024-07-05 11:07:17 +02:00
|
|
|
checkDelay();
|
2024-06-14 16:58:09 +02:00
|
|
|
shoot();
|
2024-07-05 11:07:17 +02:00
|
|
|
checkReload();
|
2024-06-14 16:58:09 +02:00
|
|
|
}
|
|
|
|
}
|