Question by
bigbear066 · Jan 09, 2018 at 01:33 AM ·
scripting problemnot workingcrashes
dont know why my script is causing unity to freeze.
very, very new to scripting in general, took 3 weeks of constant study to feel like i had a handle on it, turns out it wasnt long enough. can anyone tell me what im doing wrong? i understand the way my stuff is written is probably horrendous but like i said im new, and this is my first.
wanted a big block made of smaller blocks, it was a test. every time i run the code unity freezes, there is no compiling errors except it asking me if i meant x=x, which i do. (or dont depends on your answers :/)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class terraingen : MonoBehaviour {
public GameObject gameobject;
public float gridx = 0f;
public float gridy = 0f;
public float level = 0f;
public float spacing = 0f;
public void Start()
{
float retx = 0f;
float retz = 0f;
for (float y = 0f; y < gridy; y = y + spacing)
{
for (float x = retx; x < gridx; x = x)
{
Vector3 pos = new Vector3(x, retz, y) * spacing;
Instantiate(gameobject, pos, Quaternion.identity);
if (y == gridy)
{
retx = retx + spacing;
y = 0f;
}
else if (retx == gridx)
{
retz = retz + spacing;
retx = 0f;
}
else if (retz > level)
{
break;
}
}
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612150116im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Tree chopping 0 Answers
Unity crashes when compiling this script. Where is the problem? 0 Answers
My script is working just one time 1 Answer