Hello! I am instantiating the object with the y position being 20f, but when it spawns in it is 0. Why is that? Here is the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemySpawner : MonoBehaviour {
[SerializeField] float secondsBetweenSpawns;
[SerializeField] GameObject enemyToSpawn;
[SerializeField] int enemiesInScene;
[SerializeField] int desiredEnemiesInScene;
//[SerializeField] Transform Parent;
[SerializeField] PathFinder pathFinder;
void Start() {
StartCoroutine(Spawner());
}
IEnumerator Spawner()
{
while (enemiesInScene < desiredEnemiesInScene)
{
yield return new WaitForSeconds(secondsBetweenSpawns);
print("Spawning Enemy");
Spawn();
enemiesInScene = enemiesInScene + 1;
print(enemiesInScene);
}
if (enemiesInScene == desiredEnemiesInScene)
{
// do nothing
}
}
void Spawn()
{
float whereToSpawnEnemyX = pathFinder.startingWaypoint.transform.position.x;
float whereToSpawnEnemyZ = pathFinder.startingWaypoint.transform.position.z;
Vector3 whereToSpawnEnemy = new Vector3(whereToSpawnEnemyX, 20f, whereToSpawnEnemyZ);
Instantiate(enemyToSpawn, whereToSpawnEnemy, Quaternion.Euler(0, 90, 0));
}
}