Пытаюсь сделать выстрелы у вражеского корабля) не получается сделать так что бы направление пулей зависело от направление дула( помогите плиз вот код:
Rigidbody enemy; public Transform target;
public GameObject LaserShot;
public GameObject LaserGun;
float speed;
float shootdelay = 0.5f;
float next;
// Start is called before the first frame update
void Start()
{
enemy = GetComponent<Rigidbody>();
}
void Update() {
if (Vector3.Distance(transform.position, target.position) > 10)
{
enemy.transform.position = Vector3.MoveTowards(enemy.position, target.position, Time.deltaTime * 5);
enemy.transform.LookAt(target);
}
else
{
enemy.velocity = new Vector3(Random.Range(1, -1) * Time.deltaTime * 50, Random.Range(1, -1) * Time.deltaTime, 0);
if (Time.time > next)
{
Vector3 startgun = LaserGun.transform.position;
Quaternion startrotgun = LaserGun.transform.rotation;
Instantiate(LaserShot, startgun, startrotgun);
next = Time.time + shootdelay;
}
}
}