- Home /
getting gui error you can only call functions from inside OnGui.
I am getting the following error when i execute this script . plz help!:-
You can only call GUI functions from inside OnGUI. UnityEngine.GUIUtility.CheckOnGUI () (at C:/BuildAgent/work/aeedb04a1292f85a/artifacts/EditorGenerated/GUIUtility.cs:229) UnityEngine.GUI.get_skin () (at C:/BuildAgent/work/aeedb04a1292f85a/artifacts/EditorGenerated/GUI.cs:54) UnityEngine.GUILayout.Label (System.String text, UnityEngine.GUILayoutOption[] options) (at C:/BuildAgent/work/aeedb04a1292f85a/artifacts/EditorGenerated/GUILayout.cs:17) flap.OnGUI () (at Assets/scripts/flap.cs:61) flap.OnCollisionEnter2D (UnityEngine.Collision2D other) (at Assets/scripts/flap.cs:28)
script:-
using UnityEngine;
using System.Collections;
public class flap: MonoBehaviour
public void OnGUI ()
{
Debug.Log ("ok");
if(dead)
{
Debug.Log("working");
Time.timeScale=0;
GUI.color = Color.white;
GUILayout.Label (" Score: " + score.ToString ());
}
}
}
Answer by Em3rgency · Oct 20, 2014 at 02:48 PM
As far as I'm aware, the OnGUI() function is just like Update(), as in you don't need to call it. It will call itself whenever the internal unity magic happens. Stop calling it, everything should fix itself.
Your answer
Follow this Question
Related Questions
GUI Label Score Overlapping - Javascript 1 Answer
How to center the score in screen? 1 Answer
Can't display PNG texture within GUI calls 1 Answer
Adding score when enemy dies (Errors) 2 Answers
changing from mouse click to keys 0 Answers