So i made a WaveSpawner that spawns in enemies every 10-15 seconds but the enemies that spawn in go to the position 0,0 and not my player position. Help me fix it please.
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AImovement : MonoBehaviour
{
public GameObject player;
public float speed;
private float _distance;
public float distanceBetween = 10f;
private void Update()
{
_distance = Vector2.Distance(transform.position, player.transform.position);
Vector2 direction = player.transform.position - transform.position;
direction.Normalize();
float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
if (_distance < distanceBetween)
{
transform.position = Vector2.MoveTowards(transform.position, player.transform.position, speed * Time.deltaTime);
transform.rotation = Quaternion.Euler(Vector3.forward * angle);
}
}
}