- Home /
How to make Respawn script with time
Hello everyone i am creating a 2d game. In my game there are two objects which needs to be respawned randomly in y axis at first number of Respawning objects should be few & increase rapidly for example at start of the game the object that are Respawn will be few and it will should be slow after playing continuously the Respawning objects should increase like "Subway surfers" so i need a script for this can someone please help me .
Answer by someonethatis · Jun 10, 2020 at 06:49 PM
Try this just put the objects in the array and enter where you want the objects to spawn in x and z and enter the top spawn point and the bottom spawn point for the objects
public GameObject[] respawnObjs = new GameObject[2];
public float startSpawnSpeed;
public float speedIncrease;
float spawnSpeedCurrent;
private void Start()
{
spawnSpeedCurrent = startSpawnSpeed;
}
private void Update()
{
spawnSpeedCurrent -= Time.deltaTime * speedIncrease;
}
public float topSpawn;
public float bottomSpawn;
IEnumerator Spawn()
{
while (1 + 1 == 2)
{
Vector3 randomY = new Vector3(0,Random.Range(bottomSpawn,topSpawn),0);
yield return new WaitForSeconds(spawnSpeedCurrent);
Instantiate(respawnObjs[Random.Range(0, respawnObjs.Length)], randomY, Quaternion.identity);
}
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Instantiated object not showing in scene or hierarchy 2 Answers
,How to stop jump animtion 1 Answer
How to add a score when the correct object drags to the correct box? 1 Answer