- Home /
more cubes if there are more rounds
hi I am at unity right now and I want to send out as many cubes as in a round, for example the first round a cube is sent and the fifth round five cubes have an idea how to do it but have a hard time starting
Anyone here who has time left and wants to help?
this is my first game in unity and im kinda lost XD
I will try to interpret that but your question is a little ambiguous can you try to break it down into accurate instructions and a description of the outcome you are trying to achieve.
Is it that you are trying to create rounds of your game and each round needs to have a specific set of spawned objects?
Answer by Llama_w_2Ls · Dec 05, 2020 at 10:24 AM
I believe that you want a difficulty-ramp-up type of game where more cubes spawn each round to make it harder to complete. Quite simply, if you're keeping track of what round you're on, you can use that value as the number of cubes to be instantiated in the next round.
I don't know how you're spawning your cubes, but I would write something like this:
public class CubeSpawner : MonoBehaviour
{
public int CubesToSpawn = 1;
public GameObject Cube;
private List<GameObject> cubes = new List<GameObject>();
void Start()
{
NextRound();
}
void Update()
{
if (cubes.Count == 0)
{
NextRound();
}
}
void NextRound()
{
for (int i = 0; i < CubesToSpawn; i++)
{
// Instantiate 'Cube' 'i' amount of times
// cubes.Add('cube') adds to a list of how many cubes are left in the scene
// when destroyed, the cube is removed from the list.
}
CubesToSpawn++; // Spawns more cubes next round
}
}
This wont work if you are using scenes and will mean that the round specification would be stuck to being unidirectional and procedural.
Answer by Raijinn-sama · Dec 05, 2020 at 05:53 PM
Sorry okay I may need to add a little more clarity with my question. I'm trying to make a game where you are a cube in the middle of a plane and every round there are cubes from different directions What I am trying to do right now is to spawn cubes from different directions and that there will be as many cubes as the round that is shown, for example, if the round 5, there will be 5 cubes from different directions that you have to dodge
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class CubeSpawner : $$anonymous$$onoBehaviour { public GameObject [] spawnPoint; public GameObject spawnObject; private int spawnTotal = 2; public float timeBetweenSpawns; // Use this for initialization void Start() { spawnPoint = GameObject.FindGameObjectsWithTag("SpawnTag");
StartCoroutine(SpawnGameObject());
}
// Update is called once per frame
void Update()
{
// tryin to make the cubes rotate to the middle
gameObject.transform.position += transform.forward * 1f *Time.deltaTime;
}
IEnumerator SpawnGameObject()
{
for (var x = 0; x < spawnPoint.Length; x++)
{
Instantiate(spawnObject, spawnPoint[x].transform.position, spawnPoint[x].transform.rotation);
yield return new WaitForSeconds(timeBetweenSpawns);
}
}
}