Quantcast
Channel: Questions in topic: "unity remote"
Viewing all articles
Browse latest Browse all 297

I have this problem when I restart my game in Unity, bunch of gameObject spawns at once

$
0
0
I created this game specifically for android, but when I restart the game or when the player dies, and if I try to restart the game bunch of asteroids spawns from my spawner at once, causing the game to get laggy. Well I created a gameObject that spawns meteors 5 seconds after the previous spawn, the meteor has 4 variants and they each spawns randomly in the spawner, anyone know how to fix this? Here is my code: using System.Collections; using System.Collections.Generic; using UnityEngine; public class MeteorSpawn : MonoBehaviour { public Transform[] meteors; public Transform spawn; public int i = 0; void Start() { } void Update() { if(Time.time> i){ i += 5; int spawnRandom= Random.Range(0, meteors.Length); Instantiate(meteors[spawnRandom], spawn.position, Quaternion.identity); } } }

Viewing all articles
Browse latest Browse all 297

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>