Question by
ScreamBug · Jun 24, 2020 at 01:42 PM ·
level load
Game only works one time.
For my game I made a random level generator, but the problem is that my games works fine if I boot up unity and press play. But if I stop the game and press play again it does not work anymore. What am I doing wrong?
using UnityEngine;
public class levelGenerator : MonoBehaviour
{
public Transform levelEnd;
public Transform levelBegin;
public levelOrgeniser LO;
public GameObject[] upLevels;
private int chosenLevel;
private bool generated = false;
void Awake()
{
generated = false;
}
void Update()
{
if (LO.currentLevels < LO.maxLevels && generated == false)
{
chosenLevel = Random.Range(0, upLevels.Length);
Instantiate(upLevels[chosenLevel], levelEnd.position, Quaternion.identity);
LO.currentLevels += 1;
generated = true;
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613001703im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Why won't the next level in a sequence load after an animation? 0 Answers
Multiple levels best practise 1 Answer
Load Scene and move player to start position 0 Answers
Roll A Ball Obstacle course Question 0 Answers
Variable Scene Loader 0 Answers