Как можно исправить ошибки?
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Collection;
public class Weapon : MonoBehaviour
{
[SerializeField] private _GunType gunType;
[Space(10)]
[SerializeField] private float damage;
[SerializeField] private float fireRate;
[SerializeField] private float weaponRange;
[SerializeField] private float reloadTime;
[Header("Animation")]
[SerializeField] private string shootAnimationName;
[SerializeField] private string reloadAnimationTriggerName;
[Header("Sound")]
[SerializeField] private AudioClip empty;
[SerializeField] private AudioClip reload;
[Space(10)]
[SerializeField] private AudioClip[] shoots;
[Header("Ammo")]
[SerializeField] private string ammoObjectName;
[SerializeField] private int ammo;
[SerializeField] private int reserveAmmo;
[Header("Muzzle")]
[SerializeField] private bool haveMuzzle;
[SerializeField] private Transform muzzlePosition;
[SerializeField] private float scaleFactor;
[SerializeField] private float timeToDestroy;
[Space(10)]
[SerializeField] private GameObject[] muzzle;
[Header("Keyboard")]
[SerializeField] private KeyCode fireButton;
[SerializeField] private KeyCode reloadButton;
private enum _GunType
{
Auto,
Semi
}
private float _nextFire;
private bool _canShoot;
private Camera _cam;
private AudioSource _audioSource;
private AudioSource _audioShootSource;
private Animator _animator;
private Text ammoText;
private WeaponAmmo _weaponAmmo;
private void Awake()
{
_cam = Camera.main;
_audioSource = GameObject.FindGameObjectWithTag("Player").GetComponent<AudioSource>();
_audioShootSource = gameObject.GetComponent<AudioSource>();
_animator = gameObject.GetComponent<Animator>();
ammoText = GameObject.FindGameObjectWithTag("AmmoTextObject").GetComponent<Text>();
_weaponAmmo = GameObject.FindGameObjectWithTag(ammoObjectName).GetComponent<WeaponAmmo>();
}
private void Start()
{
_canShoot = true;
_weaponAmmo.AmmoText = ammoText;
_weaponAmmo.Ammo = ammo;
_weaponAmmo.ClipSize = ammo;
_weaponAmmo.ReserveAmmo = resrveAmmo;
}
private void Update()
{
if (_canShoot == true)
{
if (_weaponAmmo.Ammo > 0)
{
if (Time.time - _nextFire > 1 / fireRate)
{
if (gunType == _GunType.Auto)
{
if (Input.GetKey(fireButton))
{
Shoot();
}
}
else if (gunType == _GunType.Semi)
{
if (Input.GetKeyDown(fireButton))
{
Shoot();
}
}
}
}
}
if (Input.GetKeyDown(fireButton))
{
if (_weaponAmmo.Ammo <= 0)
{
_audioSource.PlayOneShot(empty);
}
if (Input.GetKeyDown(reloadButton))
{
if (_weaponAmmo.ReserveAmmo > 0 && _weaponAmmo.Ammo < Ammo)
{
StartCorutine(ReloadCoroutine());
}
}
}
private void Shoot()
{
_nextFire = Time.time;
PlayShootSound();
SpawnMuzzle();
_weaponAmmo.Ammo--;
_weaponAmmo.UpdateAmmoinScreen();
_animator.Play(shootAnimationName);
}
private void PlayShootSound()
{
AudioClip clip = null;
clip = shoots[Random.Range(0, shoots.Length)];
_audioShootSource.clip = clip;
_audioShootSource.Play();
}
private void SpawnMuzzle()
{
if (haveMuzzle == true)
{
GameObject currentMuzzle = muzzle[Random.Range(0, muzzle.Length)];
GameObject spawnedMuzzle = Instantiate(currentMuzzle, muzzlePosition.position, muzzlePosition.rotation);
spawnedMuzzle.transform.localScale = new Vector3(scaleFactor, scaleFactor, scaleFactor);
Destroy(spawnedMuzzle, timeToDestroy);
}
}
private IEnumerator ReloadCoroutine()
{
_canShoot = false;
_animator.SetTrigger(reloadAnimationTriggerName);
_audioSource.PlayOneShot(reload);
yield return new WaqitForSeconds(reloadTime);
_weaponAmmo.AddAmmo();
_weaponAmmo.UpdateAmmoinScreen();
_canShoot = true;
}
}
}