Hi all,
I have a spawner gameObject that instantiates an enemy ship. When the enemy ship gets destroyed, the spawner gameObject gets deactivated with SetActive(). After a while, when some decided action happens, the same spawner gets activated again. I want that spawner to instantiate the same gameObject again.
So my question is if I call the method that instantiates the ship in Awake(), would the enemy ship instantiate?
That’s what I understand from the documentation but I couldn’t manage to make that happen. The spawner gets enabled and spawns the ship, the ship gets destroyed and disables the spawner, after some designated action the spawner gets enabled again but does not instantiate the ship again.
This on the spawner Manager,
void NormalSpawnerDeactivator()
{
if (enemyDeathCount1 >= 20 && enemyDeathCount1 <= 22)
{
normalSpawnerIndex = 1;
if (player.transform.position.x < anchBottom.transform.position.x && instantiated==false)
{
normalSpawner1.SetActive(false);
questSpawner2.SetActive(true);
instantiated = true;
}
else if (player.transform.position.x > anchBottom.transform.position.x && instantiated == false)
{
normalSpawner1.SetActive(false);
questSpawner1.SetActive(true);
instantiated = true;
}
}
else if (enemyDeathCount1 >= 50 && enemyDeathCount1 <= 54)
{
normalSpawnerIndex = 2;
if (player.transform.position.x < anchBottom.transform.position.x && instantiated == false)
{
normalSpawner2.SetActive(false);
questSpawner2.SetActive(true);
instantiated = true;
}
else if (player.transform.position.x > anchBottom.transform.position.x && instantiated == false)
{
normalSpawner2.SetActive(false);
questSpawner1.SetActive(true);
instantiated = true;
}
}
}
void QuestSpawnerDeactivator()
{
if (isDestoryed && normalSpawnerIndex==1)
{
questCoundown -= Time.deltaTime;
if (questCoundown <= 0f)
{
questSpawner1.SetActive(false);
questSpawner2.SetActive(false);
normalSpawner2.SetActive(true);
questCoundown = 0;
instantiated = false;
isDestoryed = false;
}
}
else if (isDestoryed && normalSpawnerIndex == 2)
{
questCoundown -= Time.deltaTime;
if (questCoundown <= 0f)
{
questSpawner1.SetActive(false);
questSpawner2.SetActive(false);
normalSpawner3.SetActive(true);
questCoundown = 0;
instantiated = false;
isDestoryed = false;
}
}
}
and this is on the spawner gameObject that I want to enable and disable which is a child of the spawner manager.
private void Awake()
{
MiniBoss();
}
void MiniBoss()
{
GameObject mB = Instantiate(miniBoss, mBspawnPosition.position, Quaternion.identity) as GameObject;
Debug.Log("Instantiate");
}
The miniBoss gameObject gets destroyed through its own script and turns the bool isDestroyed = true with OnDestroy().
Thanx in advance…cheers=)