For whatever reason the line ‘clone = (BaseGameObject)Instantiate(objectToSpawn, spawnerLocation, Quaternion.identity);’ always spawns multiple objects, while this line only spawns one everytime ‘Instantiate(objectToSpawn, spawnerLocation, Quaternion.identity);’.
If it helps, during runtime I get the error ‘InvalidCastExcept: Cannot cast from source type to destination type.’ on this line;
clone = (BaseGameObject)Instantiate(objectToSpawn, spawnerLocation, Quaternion.identity);
public class ObjectSpawnPoint : BaseGameObject
{
void Update()
{
if( ... ){
BaseGameObject clone;
// Spawn multiple objs
clone = (BaseGameObject)Instantiate(objectToSpawn,
spawnerLocation, Quaternion.identity);
// Spawn only one obj
//Instantiate(objectToSpawn, spawnerLocation, Quaternion.identity);
}
}
}
The BaseObjectClass is here
public class BaseGameObject : MonoBehaviour { /*[...]*/ }
[Edit by Berenger : Removed all the unnecessary code. Full text in comments]