- Home /
Call to "Input" into a static class => null ref
Hi, I try to make my own InputManager (a static class) but when i do a call to the Unity Input class into a method (Input.GetMouseButtonDown() for example), i got a NullReferenceException once... And it works properly but i still have a error. Thanks!
Update()
{
if(Input$$anonymous$$anager.IsClicked()) // do some cool stuff
}
// ...
public static class Input$$anonymous$$anager
{
public static bool IsClicked()
{
if(Input.Get$$anonymous$$ouseButtonDown(0) || (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began))
return true;
return false;
}
}
And I got a null ref exception in the Update() function (only once!).
I think we need to know more about the class that has that update function in it. Is that the actual code for it? Why doesn't it have a return type?
Answer by flamy · Apr 04, 2014 at 12:42 PM
The best way to make managers in unity would be using Singleton pattern, it would be much better than all static classes.
Okay, but i don't really want to instantiate this class actually and i don't want it to inherit $$anonymous$$onobehaviour either...
singleton is much simple if it is not monobehaviour.... ins$$anonymous$$d of instantiate line make it as new $$anonymous$$yclass()
Your answer
Follow this Question
Related Questions
Update() in non-component script? 3 Answers
Is there a way to modify Input Manager so that an ax is be able simulate an input from code? 0 Answers
how to make a configurable input 1 Answer
InputManager doesn't detect gamepad numbers correctly 1 Answer
OnClick triggers twice because of UnityEngine.SendMouseEvents 0 Answers