- Home /
Problem with for loop
I was following this tutorial: https://www.youtube.com/watch?v=o2ntBzoeA3o∈dex=21&list=PLE5C2870574BF4B06
This for loop seems to crash Unity. Is there something wrong with it?
Not: I havn't updated to 4.6.2
for (int cnt = 0; cnt < Enum.GetValues (typeof (VitalName)).Length; cnt++ ) {
GUI.Label (new Rect (10, 40 + ((cnt + 7) * 25), 100, 25), ((VitalName)cnt).ToString());
GUI.Label (new Rect (115, 40 + ((cnt + 7) * 25), 30, 25), _toon.GetVital(cnt).AdjustedBaseValue.ToString());
}
I copied and modified that for loop from this:
for (int cnt = 0; cnt < Enum.GetValues (typeof (AttributeName)).Length; cnt++ ) {
GUI.Label (new Rect (10, 40 + (cnt * 25), 100, 25), ((AttributeName)cnt).ToString());
GUI.Label (new Rect (115, 40 + (cnt * 25), 30, 25),_toon.GetPrimaryAttribute(cnt).AdjustedBaseValue.ToString());
}
Does it crash if you make those calls outside of OnGUI?
Those are from functions being called in OnGUI Sory, should have just posted the entire script.
In what way does Unity crash? Freeze? Crash to desktop? Any errors? Can you show us how the VitalName type is defined?
If unity just freezes, wait it out and report back with error messages' content. The code itself doesn't seem to have anything faulty with it.
A freeze is typically caused by an infinite loop. This loop doesn't look infinite... Are you sure this is the problem? Does it still freeze if you comment out the for loop and just leave the GUI.Label?
Your answer
Follow this Question
Related Questions
GUI wont show in for loop 1 Answer
Push down GUI everytime for loop cycles through Array 1 Answer
Use for loops and still assign gameObjects in editor 1 Answer
Resizing an array of gameObjects 2 Answers
GUI Button and for loop not working 2 Answers