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,spawnpoint.transform.rotation); ammo--; } }else{ reload(); } } void Start() { ammo = dataBullet.ammo; muzzle = GetComponentInChildren(); spawnpoint = GameObject.Find("Player/PlayerView/BulletSpawnpoint"); } // Update is called once per frame void Update() { shoot(); } }