[SOLVED] (114) SpawnUntilFull( ) Yielding Build Errors

So I was proceeding along nicely until I reached the end of 114. Until now I’ve had no serious problems even with the Unity 4/5 mismatch.
SpawnEnemies() works great, but when I move the same code (with the exception of calling NextFreePosition(), I get the following pair of related errors, which take me to the GameObject enemy = … line of SpawnUntilFull().
One difference between my code and the original is that I have enemy ship images facing the opposite direction, which I have to turn around using the Quaternion.
I have re-keyed the script a number of times, but I can’t seem to figure out the error.
Debug.Log wasn’t particularly helpful either, but I did try just replacing the Quaternion that it’s objecting to with “true” and then it does the following:
It spawns the correct number of ships with the correct motion of the formation, only it does it at the location of the player ship (and of course, they’re facing the other direction because I didn’t have the field to turn them around). Any Ideas? I can’t figure out why it wants a bool when it’s essentially identical to the line in SpawnEnemies() that works perfectly.

Assets/Scripts/EnemySpawner.cs(89,23): error CS1502: The best overloaded method match for `UnityEngine.Object.Instantiate(UnityEngine.Object, UnityEngine.Transform, bool)’ has some invalid arguments

Assets/Scripts/EnemySpawner.cs(89,23): error CS1502: The best overloaded method match for `UnityEngine.Object.Instantiate(UnityEngine.Object, UnityEngine.Transform, bool)’ has some invalid arguments

bool AllMembersDead(){
	foreach(Transform childPositionGameObject in transform){
		if (childPositionGameObject.childCount > 0){
			return false;
		}
	}
	return true;
}

Transform NextFreePosition(){
	foreach(Transform childPositionGameObject in transform){
		if (childPositionGameObject.childCount == 0){
			return childPositionGameObject;
		}
	}
	return null;
}

void SpawnEnemies(){
	foreach(Transform child in transform){
		GameObject enemy = Instantiate(enemyPrefab, child.transform.position, Quaternion.Euler(180,0,0)) as GameObject;
		enemy.transform.parent = child;
	}
}

void SpawnUntilFull(){
	Transform freePosition = NextFreePosition();
	if(freePosition){
		GameObject enemy = Instantiate(enemyPrefab, freePosition, Quaternion.Euler(180,0,0)) as GameObject;
		enemy.transform.parent = freePosition;
	}
	Invoke("SpawnUntilFull", spawnDelay);

The error is in this line, inside SpawnUntilFull:

you’re passing a Transform instead of a Vector3, the correct syntax is:

1 Like

Awesome! Thanks.

Privacy & Terms