How to Instantiate Enemy in Infinite running Game?

Hello, I am 15 years old and I am new to unity scripting. I am creating an Infinite game, where I am want to instantiate my enemy in front of my Player. When I am Instantiate My Enemy in the Player Position, My Player is Moving and My enemy goes behind the Player. So, I am want to Instantiate My enemy in front of player before some distance. So, I watched more tutorials on YouTube, but nothing clears my Question. So, Please Help Me!
Below Code to Instantiate My Surface of the Game.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TilePrefabs : MonoBehaviour
{
    public GameObject tilePrefabs;
    private Transform playerTransform;
    private float spawnZ = 0.0f;
    private float tileLength = 4900f;
    public float safeZone = 5200f;
    private int amnTilesOnScreen = 10;
    public List<GameObject> activeTiles;

    void Start()
    {
        activeTiles = new List<GameObject>();
        playerTransform = GameObject.FindGameObjectWithTag("Player").transform;
        for (int i = 0; i < amnTilesOnScreen; i++)
        {
            SpawnTile();
        }

    }

    // Update is called once per frame
    void Update()
    {
        if (playerTransform.position.z - safeZone > spawnZ - amnTilesOnScreen * tileLength)
        {
            SpawnTile();
            DeleteTiles();

        }

    }

    private void SpawnTile(int prefabindex = -1)
    {
        GameObject go;
        go = Instantiate(tilePrefabs) as GameObject;
        go.transform.SetParent(transform);
        go.transform.position = Vector3.forward * spawnZ;
        spawnZ += tileLength;
        activeTiles.Add(go);
    }

    public void DeleteTiles()
    {
        Destroy(activeTiles[0]);
        activeTiles.RemoveAt(0);

    }
}

In exactly the same way you are spawning the tiles i.e. playerTransform.forward * distanceAwayFromPlayer.


That said it is probably a better idea to spawn them relative to the tiles local positioning ahead of time. i.e. nesting them under the spawned tile so their cartesian space is relative to the tile.


That way you can easily place your enemies on the next/ upcoming tiles and then when your player gets to them they will already be in place.