Не понимаю почему не работают корутина в игре на Unit
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerFire : MonoBehaviour, IFire
{
private readonly Rigidbody2D _bullet;
private readonly Transform _barrel;
private readonly float _force;
private readonly float _fireRate;
public PlayerFire(Rigidbody2D bullet, Transform barrel, float force, float fireRate)
{
_bullet = bullet;
_barrel = barrel;
_force = force;
_fireRate = fireRate;
}
public void Fire(float fireButton)
{
if (fireButton == 1)
{
StartCoroutine(FireWithRate());
}
}
private IEnumerator FireWithRate()
{
var temAmmunition = Instantiate(_bullet, _barrel.position, _barrel.rotation);
temAmmunition.AddForce(_barrel.up * _force);
yield return new WaitForSeconds(1);
}
}
Не понимаю почему выбрасывает
NullReferenceException
UnityEngine.MonoBehaviour.StartCoroutine (System.Collections.IEnumerator routine) (at <d3b66f0ad4e34a55b6ef91ab84878193>:0)
PlayerFire.Fire (System.Single fireButton) (at Assets/PlayerFire.cs:22)
Ship.Fire (System.Single fireButton) (at Assets/Ship.cs:44)
Player.Update () (at Assets/Player.cs:48)
Все ссылки переданы, все объекты у класса есть, но работать не хочет(