I’m trying to create a script where I make certain enemies appear less often than others. I’m also trying to make it so after the enemies are destroyed they can regenerate at a certain pace.
I know I should use random and time factors but I’m not sure how to script this (I assume its separate scripts)
The thing that has helped me the most is to break down scripting and focus on one piece at a time.
First just try to get enemys to spawn… then focus on tweeking the script to get more functionality out of it.
but to get you started on the right foot, i would use coroutine and IEnumerator to do this.
I’m sure you could add random functionality to the delay timer to get closer to what your trying to acheive.
If you need to understand any part of this, try searching the unity scripting manual.
// Public gameobject where you will drag the prefab you want to spawn.
public GameObject spawnEnemy;
public float delayTime = 5f;
void Start ()
{
StartCoroutine(EnemySpawnTimer());
}
// Function type that allows us to use wait function.
IEnumerator EnemySpawnTimer()
{
while(true)
{
// Spawn game object whereever the object of the script is located.
Instantiate(spawnEnemy, transform.position, Quaternion.identity);
// Wait for seconds befor continueing the loop.
yield return new WaitForSeconds(delayTime);
}
}