- Home /
My Blockspawner bugging out as it spawns more frequently.
Hi guys,
I'm creating my first game (infinite block dodging game)
I seem to have trouble with my blockspawner ever since I adjusted it so it spawns more frequently as time goes on.
I designed the game so the blocks have a rigidbody component and it must bug out when the blocks spawn too fast and overlap on each other.
public class BlockSpawner : MonoBehaviour
{
public Transform[] spawnPoints;
public GameObject blockPrefab;
public List<Color> TintColors;
public float timeBetweenWaves = 0f;
//how many seconds before block spawns
private float timeToSpawn = 0f;
void Update()
{
if (Time.time >= timeToSpawn)
{
SpawnBlocks();
timeToSpawn = Time.time + timeBetweenWaves;
timeBetweenWaves *= 0.9f;
}
}
//spawning blocks in all 3 lanes
void SpawnBlocks()
{
var shuffle_colors_list = TintColors.OrderBy(a => Random.value).ToList();
for (int i = 0; i < 3; ++i)
{
var go = Instantiate(blockPrefab, spawnPoints[i]);
go.GetComponent<Renderer>().material.color = shuffle_colors_list[i];
}
}
}
This is my code above, I was wondering if anyone can advise on it or if I can somehow adjust the block so it doesn't interfere with the other blocks?
Thanks guys!
perhaps you have to be a bit more specific on what you are trying to achive.
The spawning works fine but you want the blocks to not interact with eachother in case they spawn over each other?
In case that is your question just put them on a layer that you call "Blocks" or something. Then go to the project physics settings an disable collisions between between the block layer and other things on the block layer.
Or use triggers.
Hope this helps.