Не работает анимация отдачи в Unity(
В общем, у меня есть скрипт стрельбы и при выстреле должна проиграться анимация стрельбы
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Стрельба : MonoBehaviour
{
public GameObject bullet;
public GameObject dulo;
public int maxammo;
public float nexttimetofire;
public float firerate;
public int currentammo;
public float reloadtime;
public bool reload;
public AudioSource shoot;
public ParticleSystem fire;
public AudioSource reloading;
public Text ammotext;
public Text maxammotext;
public float razbros;
public AudioClip shooot;
public string ShootAnim;
public string ReloadAnim;
private void Start()
{
currentammo = maxammo;
}
void Update()
{
maxammotext.text = "/" + maxammo.ToString();
ammotext.text = currentammo.ToString();
if (reload)
{
return;
}
if(currentammo <= 0)
{
GetComponent<Animator>().Play(ReloadAnim);
StartCoroutine(Reload());
return;
}
if (Input.GetKey(KeyCode.Mouse0) && Time.time >= nexttimetofire && currentammo > 0)
{
GetComponent<Animator>().Play(ShootAnim);
nexttimetofire = Time.time + 1f / firerate;
--currentammo;
Shoot();
shoot.PlayOneShot(shooot);
fire.Play();
}
}
IEnumerator Reload()
{
reload = true;
reloading.Play();
yield return new WaitForSeconds(reloadtime);
currentammo = maxammo;
reload = false;
}
public void Shoot()
{
GetComponent<Animator>().Play(ShootAnim);
GameObject bulletobj = Instantiate(bullet);
bulletobj.transform.position = dulo.transform.position + dulo.transform.forward;
bulletobj.transform.forward = dulo.transform.forward;
bulletobj.transform.rotation = dulo.transform.rotation * Quaternion.Euler(Random.Range(-razbros, razbros), Random.Range(-razbros, razbros), 0);
}
}
Вверху сам код собсна
И вот: анимация перезарядка вопроизводится корректно, но отдача проигрывается только ОДИН раз после перезарядки. Я не знаю как это решить, не понимаю что не так, помогите пожалуйста