using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemySpawner : MonoBehaviour
{
    [SerializeField]
    private Enemy _enemyToSpawn;
    [SerializeField]
    private Player _player; // Needed so the enemies know who to chase
    [SerializeField]
    private float _interval = 10f;
    [SerializeField]
    private float _offset = 0f;

    private float timeSinceLastSpawn = 0;
    private bool _doubleSpeed = false;

    private void Start() {
        timeSinceLastSpawn -= _offset;
    }

    private void Update() {
        timeSinceLastSpawn += Time.deltaTime;
        if (timeSinceLastSpawn > _interval) {
            timeSinceLastSpawn -= _interval;
            SpawnEnemy();
        }
    }

    private void SpawnEnemy() {
        Enemy enemy = Instantiate(_enemyToSpawn, transform.position, transform.rotation);
        if (_doubleSpeed) {
            enemy.DoubleSpeed();
        }
        enemy.player = _player;
    }

    public void SetDoubleZombieSpeed() {
        _doubleSpeed = true;
    }
}
