1
\$\begingroup\$

I want once run GUI on screen same Initialization a number. I try say my think In easiest way then please payattention to this code:

using UnityEngine;
using System.Collections;

public class guimanager : MonoBehaviour {
    public bool Isdone;
     void OnGUI()
    {
            for (int j = 0; j <= 100; j+=20) {
            if (Isdone == true) {
                break;
            }

            GUI.Box(new Rect(j, j, Screen.width/2, Screen.height/2), "This is a test");
                print (j);
            }
        }
    }

I want keep my GUI.Box When end loop,So I need a boolean that when finish stop loop.

my problem Is frequent loop:

0,1,2,3,4,5,0,1,2,3,4,5,0,1,2,3,4,5,0,1,2,3,4,5,0,1,2,3,4,5,......

GUI.Box will Show

but When I want break my loop:

0,1,2,3,4,5

GUI.Box won't Show!!!!

Can I show my GUI.boxes In my loop when finished?

using UnityEngine;
using System.Collections;

public class guimanager : MonoBehaviour {
    public bool Isdone;
     void OnGUI()
    {
            for (int j = 0; j <= 100; j+=20) {
            if (Isdone == true) {
                break;
            }

            GUI.Box(new Rect(j, j, Screen.width/2, Screen.height/2), "This is a test");
                print (j);
            }
Isdone = true;
        }
    }

Why when I stop loop GUI.Box won't show!!!

\$\endgroup\$
  • \$\begingroup\$ You need to follow the coding standards for C#, for things like variable names and indentation. Heck, at the very least, pick one and be consistent. (Note: I'm not entirely certain that Microsoft has official style standards, but I think they do) \$\endgroup\$ – Fund Monica's Lawsuit Feb 15 '16 at 0:48
1
\$\begingroup\$

Because you are showing GUI.Box in your for loop after break. That is preventing your GUI.Box to draw.

What you have to do is simply draw your GUI.Box outside the for-loop. You can do it in a little bit better way, like,

using UnityEngine;
using System.Collections;

public class guimanager: MonoBehaviour
{
    public bool _isDone = false;

    void OnGUI ()
    {
        for (int j = 0; j <= 5; j++) {
            GUI.Box (new Rect (j * 20, j, Screen.width, Screen.height), "This is a test");
            if (_isDone)
                continue;
            print (j);
        }
    _isDone = true;

    }
}
| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Is there any way that I use arry GUIes?????GUI.Box (new Rect (j,j, Screen.width, Screen.height), "This is a test"); I want have loop GUI for example: if j ==5 > for loop > i have five GUI.Boxes [] [] [] [] [] [] \$\endgroup\$ – Seyed Morteza Kamali Feb 15 '16 at 3:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.