using System.Collections; using System.Collections.Generic; using UnityEngine; public class WeaponManager : MonoBehaviour { public enum WeaponType { None, Shoot, Meele }; public WeaponType weaponType = WeaponType.None; public float weaponRange = 1; public GameObject spawnShoot; public GameObject particleShoot; public float damage = 0; public float fireRate = 0.5f; private float fireTime; public int ammoCost = 2; public Animator animator; public PlayerManager player; public bool hit = false; public AudioSource audioSource = new AudioSource(); public List shootSound = new List(); // Start is called before the first frame update void Start() { fireTime = fireRate; } // Update is called once per frame void Update() { WeaponAttack(); } public void WeaponAttack() { if (Input.GetMouseButtonDown(0) && fireTime <= Time.time) { if (weaponType == WeaponType.Shoot) { if (particleShoot != null && player.ammo > (ammoCost - 1)) { GameObject shoot = Instantiate(particleShoot, spawnShoot.transform.position, spawnShoot.transform.rotation); if (shootSound.Count > 0) { int rand = Random.Range(0, shootSound.Count); audioSource.PlayOneShot(shootSound[rand]); } player.ammo -= ammoCost; Destroy(shoot, 0.3f); fireTime = fireRate + Time.time; } } else if (weaponType == WeaponType.Meele) { hit = true; animator.ResetTrigger("Hit"); animator.SetTrigger("Hit"); fireTime = fireRate + Time.time; } } if (fireTime <= Time.time) { hit = false; } } }