-1

Hallo how to use the field without using a static please ? I cant use "this" in static but when I remove "this" I have the following problem: an object reference is required for the non-static field method or property unity 'Game.Open'

private bool Open;
    // Token: 0x06001748 RID: 5960
    public static void Menu()
    {

            if (SceneManager.GetActiveScene().name == "MainMenu")
            {

                        if (Open)
                        {
                            Open = true;
                        }
                        else
                        {
                            Open = false;

                        }
            }
    }
Ruzihm
  • 19,749
  • 5
  • 36
  • 48

1 Answers1

0

Brief : private static bool Open; <- static variable for static method

You method is static (belongs to the class, there is only one). Your variable is not (belongs to the object there can be many) :.
There is only one Menu (I guess) so put the variable static. (And avoid the whole if anti-pattern). Is that ok :

private static bool Open;

// Token: 0x06001748 RID: 5960
public static void Menu(){
       if (SceneManager.GetActiveScene().name != "MainMenu"){return;}

       if (Open){Open = true;}
       else{Open = false;} 
}

See here : https://syntaxdb.com/ref/csharp/static-methods
Static methods are called without instantiation. This means that static methods can only access other static members of the class (and of course, global and passed in variables), because other members are object members.

Tinmarino
  • 3,693
  • 24
  • 33