NullReferenceException: Error from the GetStyle() - Method
Hey guys, I'm pretty new to Unity, respectively C#, and I'm currently making a small game. So here's my problem: I have a little timer in the left corner on the screen, telling the player, that he should hurry up, otherwise he'll die. But that's not the big issue. The timer seems not to be that user friendly and so I decided to give him a custom GUI Skin. You know, custom font, font size, and so on. And I named this Custom Style: "Timer". So far so good. As I finished writing the code, I tested it out and I got the following error message: "NullReferenceException: Object reference not set to an instance of an object Gamemanager.OnGUI () (at Assets/Scripts/Gamemanager.cs:50)". The GameManager is just a regular class. And this is my code:
public GUISkin skin;
void OnGUI()
{
GUI.skin = skin;
GUI.Label(timerRect, CurrentTime, skin.GetStyle("Timer"));
}
Thanks to anyone who could help me :D
And the timerRect + CurrentTime are just there for the timer. But they're not that important for the error message.
Answer by mimidaso · Apr 11, 2017 at 11:10 AM
Hey guys, I solved it myself. The problem was, that I didn't attach the GUI Skin, to the GameManager. So. yeah.
Your answer
Follow this Question
Related Questions
UnassignedReferenceException: The variable UI of MenuManager has not been assigned. 1 Answer
Nav Mesh Problem with SetDestination 1 Answer
Brackeys Multiplayer fps tutorials trouble.. 0 Answers
Error: -Has an extra field and can't be serialized 1 Answer
Unable to join player connection alternative multicast group. 1 Answer