I can't load play mode
I tried to make a random map creator using multiple cubes of differents heigth,i also tried to implement a hole in the center of the map.I made a script which does that, but when i try it and enter play mode it load forever. This is my code:
public float mapX;
public float mapY;
public float insideX;
public float insideY;
float constantX;
float constantY;
public GameObject prefab;
Vector3 myPosition;
// Start is called before the first frame update
void Start()
{
constantX = mapX;
constantY = mapY;
}
// Update is called once per frame
void Update()
{
while (mapY > -constantY)
{
while (mapY > insideY||mapY<-insideY)
{
while (mapX > -constantX)
{
myPosition = new Vector3(mapX - 0.5f, 0, mapY - 0.5f);
GameObject Myprefab = Instantiate(prefab, myPosition, Quaternion.identity) as GameObject;
Myprefab.transform.parent = GameObject.Find("outsideMap").transform;
mapX--;
}
mapX = constantX;
mapY--;
}
while (mapY < insideY ||mapY>-insideY)
{
if (mapX < insideX || mapX > -insideX) {
mapX++;
}
while (mapX>insideX||mapX<-insideX) {
myPosition = new Vector3(mapX - 0.5f, 0, mapY - 0.5f);
GameObject Myprefab = Instantiate(prefab, myPosition, Quaternion.identity) as GameObject;
Myprefab.transform.parent = GameObject.Find("outsideMap").transform;
mapX--;
}
mapX = constantX;
mapY--;
}
}
}
Is the variable insideY positive or negative (i.e smaller or bigger than 0)
Answer by Mathias123456 · Dec 07, 2019 at 01:09 AM
The first while loop is stopping the map from repeating every frame(once the value of mapY<-constantY). I tested your theorie to be sure and it still didn't work.Thank for your answer anyway.
Alright, can you tell me the values for each variables and constants in the begining please? I'll try it out and try to make it work.
Answer by Guy_Yome · Dec 07, 2019 at 12:57 AM
I have something to point out. You seem to instantiate the whole map every frame, not only once. It seems to be too intense, since it will never stop and fill memory. Would you not want to put it in the start function instead?
Your answer
Follow this Question
Related Questions
Stuttering in build 0 Answers