Unity Community


Results 1 to 4 of 4

  1. Location
    NA
    Posts
    628

    script error: OnGUI() can not be a coroutine

    script error: OnGUI() can not be a coroutine -> this is
    the error i get with this script. Any idea what is wrong?


    var lockedGUI : GUITexture;
    var iconlevel1 : Texture2D;
    var iconlevel2 : Texture2D;

    function OnGUI () {
    if (GUI.Button (Rect (10,10, 100, 50), iconlevel1)) {
    print ("you clicked the icon");
    Application.LoadLevel("1");
    }

    if (GUI.Button (Rect (10,70, 100, 20), "Support/Manual")) {
    print ("you clicked the text button");
    }

    if (GUI.Button (Rect (10,90, 100, 50), iconlevel2)) {
    if (PlayerPrefs.GetInt("2", -1) != -1)
    {
    Application.LoadLevel("2");
    }
    else
    {


    lockedGUI.gameObject.active = true;
    yield new WaitForSeconds (3);
    Destroy (this);
    lockedGUI.gameObject.active = false;

    }
    }

    }
    Fundi


  2. Location
    Zürich, Switzerland
    Posts
    26,572
    you can not yield in OnGUI
    Also there is no reason for it, as OnGUI is called twice per frame (once for rendering, once for the input handling), independent if the previous one has ended or not.


  3. Location
    NA
    Posts
    628
    so, how can i make it so it stay on the screen for a few second and than disssapear?
    Fundi


  4. Location
    Zürich, Switzerland
    Posts
    26,572
    You have a variable that tracks when the gui object has been started with drawing and after a given amount of time has passed since that point you do not draw it anymore.
    GUI stuff does not stay on screen, if you do not call the function anymore on the next frame, the gui object is just not present anymore

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •