MaximGS090909
@MaximGS090909

Почему выходят ошибки «modifier 'private' is not valid for this item»?

Как можно исправить ошибки?
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;
        }
    }
}


62fe7b4e886ff434810089.png
  • Вопрос задан
  • 197 просмотров
Решения вопроса 1
Не закрыл фигурную скобку у Update, и получилось так, что функция Shoot и другие стали локальными (внутри Update).
У локальных функций нет модификатора доступа, тк они и так доступны только внутри тех методов, в которых они объявлены.
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы