- Home /
Question is off-topic or not relevant
Level Generator porblem
Im making a game where the player has to climb up cubes, the Level generator generates 40 pieces at the start and I want it to add 20 every time the player reaches 20 more. So if hes at the 20 cubes 20 more spawn if hes at the 40 cubes 20 more spawn ...
I have a function to spawn 20 cubes, I only need to make a script that checks if the player reached 20 cubes and then call the spawn function MakeLevel(); once.
You're not telling us much. Where are the cubes placed? Is this a 3D game?
Without those details, we can't find a way to detect how many cubes the player has climbed, which I'm sure is the reason you asked this question.
Is that any math question from school? YOu should provide more detail about it as allenallenallen said
Answer by malkere · Dec 26, 2015 at 05:31 AM
allenallenallen is right in that we kinda need more than that.... but, are you jumping up on the y axis? how about if the player.transform.position is equal or greater than 20 you call MakeLevel() ?
I figured it out myself, here are the scipts:
Spawns 40 cubes at start:
private void $$anonymous$$akeLevel() {
number = UnityEngine.Random.Range (0, colors.Length);
material.color = colors[number];
for(int i = 0; i < 40; i++) {
if(i == amountToSpawn - 1) {
g = Instantiate<GameObject>(endPlatformPrefab);
} else if(i == 0) {
g = Instantiate<GameObject>(startPlatform);
} else {
g = Instantiate<GameObject>(platformPrefab);
}
g.transform.parent = transform;
spawnedBlocks.Add(g);
if(i == 0) {
lastPos = g.transform.position;
continue;
}
if(i < amountToSpawn) {
if(g.GetComponent<Platform>() != null && i != amountToSpawn - 1) {
float chanceOfObstacle = 1f;
if(i > 20) {
chanceOfObstacle = 0.75f; // 20%
}
if(i > 40) {
chanceOfObstacle = 0.6f;
}
if(i > 60) {
chanceOfObstacle = 0.5f;
}
if(i > 80) {
chanceOfObstacle = 0.4f;
}
if(i > 100) {
chanceOfObstacle = 0.2f;
}
float c = UnityEngine.Random.value;
if(c > chanceOfObstacle) {
g.GetComponent<Platform>().EnabledAsObstacle();
}
}
}
int left = UnityEngine.Random.Range(0, 2);
if(left == 1) {
g.transform.position = new Vector3(lastPos.x - blockWidth, lastPos.y + blockHeight, lastPos.z);
} else {
g.transform.position = new Vector3(lastPos.x, lastPos.y + blockHeight, lastPos.z + blockWidth);
}
lastPos = g.transform.position;
}
}
}
$$anonymous$$akes a new cube spawn when the player gets higher:
private void PopupStep(EventObject evt) {
steps++;
score.text = steps.ToString();
levelgenerator.$$anonymous$$akeLevel2();
}
$$anonymous$$akeLevel2 just spawns one new cube.
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Strange random seed issue with level generation 1 Answer
How can I end a level and go to the next level 1 Answer
How to use Hashtables? 0 Answers