I made so that the Spawner parent game object managed the waves (using scriptable objects).
But then I remarked that my attackers were still spawned to the attackers parent gameobject, instead of the lanes (children of spawner parent game object). I needed to change my spawndirector script, like this:
public class SpawnDirector : MonoBehaviour
{
public SpawnQueue Queue;
// Use this for initialization
void Start()
{
if (!Queue)
{
Debug.LogError("SpawnQueue is missing in: " + name);
return;
}
foreach (Spawn item in Queue.SpawnsList)
{
StartCoroutine(Spawn(item));
}
}
IEnumerator Spawn(Spawn spawnData)
{
yield return new WaitForSeconds(spawnData.SpawnTimeAfterQueueHasStarted);
GameObject spawnedAttacker = Instantiate(spawnData.PrefabToSpawn);
spawnedAttacker.transform.parent = spawnData.PositionToSpawnTo;
}
}
My attackers get spawned but at 0,0 because:
“Setting the parent of a transform which resides in a prefab is disabled to prevent data corruption.
UnityEngine.Transform:set_parent(Transform)
c__Iterator0:MoveNext() (at Assets/Scripts/SpawnDirector.cs:27)
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)”
Any idea on how to fix this?
It is to note the following, here’s an instance of the scriptable object I’m using:
http://imgur.com/KN3aDLN
The position to spawn is actually the children of the spawners prefab (laneX). Would that be the problem? And if yes, how else could I do what I want to do?
