Мне удалось справиться с некоторыми уроками с YouTube, но у меня возникла проблема (очевидно).
Я пытаюсь добавить в свою игру полностью автоматическое оружие.
Но проблема, с которой я столкнулся, заключается в том, что как только я нажимаю кнопку огня (используя действие ввода стартовых ресурсов Unity), пистолет не включается. прекратите стрельбу, если только у него не закончатся патроны. Но как только перезагрузка завершится, он снова опустошится.
Как это предотвратить?
Код: Выделить всё
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using StarterAssets;
using System;
public class Rifle : MonoBehaviour
{
[SerializeField] private GameObject _reload;
private StarterAssetsInputs _input;
[SerializeField] private GameObject bulletPrefab;
[SerializeField] private GameObject Bullet_Point;
public Animator _animator;
public float bulletspeed = 600;
public static int maxShotsRifle;
private int shotCount;
private bool isReloading = false;
private bool isShooting = false;
public static int canbereloaded;
public float shootCD;
void Start()
{
if (maxShotsRifle == 0)
{
maxShotsRifle += 15;
}
_input = transform.root.GetComponent();
shotCount = maxShotsRifle;
}
void Update()
{
canbereloaded = maxShotsRifle - 1;
if (_input.shoot && !isShooting && !isReloading && shotCount >= 1)
{
StartCoroutine(Shooting());
}
if (shotCount
Подробнее здесь: [url]https://stackoverflow.com/questions/79179732/how-to-insert-a-cooldown-for-shoots-for-an-automatic-weapon-in-unity[/url]