Я делаю врага, который будет стрелять в игрока. Я поворачиваю пул во время его появления и пытаюсь запустить его, но по какой-то причине он не двигается
У меня есть два скрипта для скрипта пули и скрипт для врага, который стреляет пулями
Сначала я пытался сделать движение пули с помощью AddForce(transform.up * Speed);
![image](https://i.stack.imgur.com/YSlxa.png)
Для пули
public class BulletScript : MonoBehaviour
{
public GameObject bullet;
void Start()
{
bullet.transform.Translate(bullet.transform.forward * Time.deltaTime);
}
}
для врага
public class TurelScript : MonoBehaviour
{
public Transform Player;
public Transform Turell;
public GameObject PrefabOfbullet;
public Transform BUlletPosition;
public float Rotation;
void Start()
{
var turnOfBullet = Quaternion.Lerp(BUlletPosition.rotation, Quaternion.LookRotation(Vector3.forward, Player.position - BUlletPosition.position), Time.deltaTime * 40f);
var rigidbodyBullet = GetComponent<Rigidbody2D>();
StartCoroutine(BulletSpawn());
}
// Update is called once per frame
void Update()
{
var turn = Quaternion.Lerp(Turell.rotation, Quaternion.LookRotation(Vector3.forward, Player.position - Turell.position), Time.deltaTime * 4f);
var rigidbody = GetComponent<Rigidbody2D>();
rigidbody.MoveRotation(turn.eulerAngles.z);
}
IEnumerator BulletSpawn()
{
while (true)
{
Instantiate(PrefabOfbullet, BUlletPosition.position, Turell.rotation);
yield return new WaitForSeconds(0.3f);
}
}
}