- Home /
Question by
RaulG · Mar 11, 2015 at 08:53 AM ·
guinullreferenceexception
Null Reference exception bug?
NullReferenceException: Object reference not set to an instance of an object
UnityEngine.GUI.HandleTextFieldEventForDesktop (Rect position, Int32 id, UnityEngine.GUIContent content, Boolean multiline, Int32 maxLength, UnityEngine.GUIStyle style, UnityEngine.TextEditor editor) (at C:/buildslave/unity/build/artifacts/generated/common/runtime/GUI.gen.cs:722)
UnityEngine.GUI.DoTextField (Rect position, Int32 id, UnityEngine.GUIContent content, Boolean multiline, Int32 maxLength, UnityEngine.GUIStyle style) (at C:/buildslave/unity/build/artifacts/generated/common/runtime/GUI.gen.cs:557)
UnityEngine.GUI.TextField (Rect position, System.String text, UnityEngine.GUIStyle style) (at C:/buildslave/unity/build/artifacts/generated/common/runtime/GUI.gen.cs:450)
UniversalStats.OnGUI () (at Assets/UniversalStats.cs:34)
Thats the error and it points to:
public void OnGUI ()
{
GUI.TextField (new Rect(Screen.width - 215,Screen.height - 550,0,0),"Score: " + gameScore, scoreTexture);
}
I've used that line in different areas, and it hasn't caused problems before!
if (gameScore > 0) {
GUI.TextField (new Rect (Screen.width - 215, Screen.height - 550, 0, 0), "Score: " + gameScore,scoreTexture);
}
Had to change it to the above line in order to not break it. Can anyone explain why?
Comment