Hi
I need a help, I wish to create a list of GUILabels on OnGUI.
I create list from Array , this is a script :
function OnGUI () {
// An absolute-positioned example: We make a scrollview that has a really large client
// rect and put it in a small rect on the screen.
scrollPosition = GUI.BeginScrollView (Rect (20,10,440,210),
scrollPosition, Rect (0, 0, 400, 800),false,true);
for (var value : String in arr)
{
GUI.Label (Rect (80, 20 + yOff, textureToDisplay.width, textureToDisplay.height),textureToDisplay);
GUI.Label (Rect (160, 20 + yOff + 20, textureToDisplay.width, textureToDisplay.height), value,customGuiStyle);
if (GUI.changed) {
GUI.changed = false; // reset the value, so we can detect the next one
yOff=20;
}else {
yOff+=20;
}
}
.
GUI.EndScrollView ();
}
Found this because I am trying to do the same, and OnGUI seems to be offended by my use of a for loop? I might be having an airgap but I can’t reckon how to perform an action for each item in an array? It says “can only be called in OnGUI”. This is so infuriating because it’s such a simple thing to perform in Grasshopper Rhino. So, absurdly, fundamental. I need to display the mesh face indices, so I can write them tf down, so I can assign actions according to create an actually useful collisionFlag enumerator. For legibility, I center them on the face, horizontal to view. I just can’t believe that through all this parsing information, mostly offered by volunteers, that Unity expects me to fork over 30% of profit when this is all said and done. At least I’m learning to code, which I might just take over to Godot. If I figure this out I’ll reply with my code.
One of the ways to improve that experience is to post a clear question (possibly with relevant code) in your own new fresh post, rather than hijacking an 11-year-old post that shares perhaps nothing in common with your problem.
We know arrays can be handled in OnGUI because … well, I do it all the time. Look at any one of my games.
If you would like to make a fresh post of your own to restate your question clearly with a small snippet of relevant code, here is how to report your problem productively in the Unity3D forums:
Like Kurt said, if you have a concrete issue, you should create your own post. I once created this IMGUI crash course on UnityAnswers which might be useful. I don’t really see what could possibly be the issue with a loop inside OnGUI. As Kurt said, we use it all the time. I created countless editor tools that uses loops, like this sceneview camera preset script.
Thank you for responding, and so quickly. Yes, I had accidentally commented out a curly bracket. I still have a problem which does still seem significant re: face vertex stability & calls. PS: Hijack is a strong word for picking up a hanging thread. I’ll init a new thread.