unity3d - An Object reference is required to access non-static member C# Unity - How do I fix? -


this question has answer here:

i keep getting following error

assets/zoning.cs(12,30): error cs0120: object reference required access non-static member `playercontroller.addfuel(float)'

void ontriggerenter2d(collider2d collider) {     if (collider.tag == "player")     {         debug.log("player re-fueling");         playercontroller.addfuel(1);     } 

you must create instance of class in order access functions inside it.

 playercontroller obj = new playercontroller();  void ontriggerenter2d(collider2d collider) {      if (collider.tag == "player")      {          debug.log("player re-fueling");           obj.addfuel(1);      } 

Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -