Static variable error

I have 2 c# scripts and I am trying to access a boolean variable from one of them in the other one. Everything seems to be public, so it seems like I should be able to access the variable. I receive an error though that says “An object reference is requred to access non-static member FinishLevel.Level1Complete”. Here are the scripts:

using UnityEngine;
using System.Collections;


public class FinishLevel : MonoBehaviour {
	
	public bool Level1Lost;
	public bool Level1Complete;
	// Use this for initialization
	public void Update () {
		if(Level1Complete){
			Application.LoadLevel("Win 1");
		}		
		if(Level1Lost){
			Application.LoadLevel ("LostLevel1");
		}
	}
	
	// Update is called once per frame
	public void OnTriggerEnter(Collider other){
		if(GameObject.FindWithTag ("Finish")){
			Level1Complete = true;
		}
		if(GameObject.FindWithTag ("DeathZone")){
			Level1Lost = true;
		}
	}
}

And I am trying to access Level1Complete variable using this one:

using UnityEngine;
using System.Collections;

public class LevelSelectGUI : MonoBehaviour {

	public GUIStyle l1Style;

	void OnGUI () {
		if(GUI.Button(new Rect(Screen.width/2+180,Screen.height/2-60,40,40),"1", l1Style)){
			if(FinishLevel.Level1Complete){
				Application.LoadLevel ("Level 1");
			}
	
		}
	}
}

Instance variable:

public bool Level1Lost;

Static variable:

public static bool Level1Lost;

The key difference is whether the variable is associated with an object (each FinishLevel object has its own copy of the variable) or with the class (there is only one variable, which is shared by every object that can access it).

If you’re not clear on the difference, Google around for a few articles or blog posts and find one that makes sense to you.

One note specific to Unity: remember that a static variable will not be automatically reset when you load a new scene. You can reset it yourself easily enough, as long as you’re careful.

Having loads of public static variables tends to make code hard to debug and maintain. It is sometimes an acceptable band-aid for simple flags, counters, and the like.

As @rutter said, Level1Lost is a instance variable: it exists in every instance of FinishLevel. Since many objects may have a FinishLevel instance attached, you must define which object you’re interesting in, then get a reference to its FinishLevel script in order to access its variable Level1Lost. Supposing that the object you want is called “LevelControl”, you could get the instance reference like this:

using UnityEngine;
using System.Collections;
 
public class LevelSelectGUI : MonoBehaviour {
     
    public GUIStyle l1Style;
    private FinishLevel finishLevelScript;

    void Start(){
        // get a reference to the object you want:
        GameObject levelCtrl = GameObject.Find("LevelControl");
        // get a reference to its FinishLevel script:
        finishLevelScript = levelCtrl.GetComponent<FinishLevel>();
    }

    void OnGUI () {
        if (GUI.Button(new Rect(Screen.width/2+180,Screen.height/2-60,40,40),"1", l1Style)){
            // access the variable via script reference:
            if (finishLevelScript.Level1Complete){
                Application.LoadLevel ("Level 1");
            }
        }
    }
}

But if you only has a single instance of FinishLevel in your whole game, you may declare Level1Complete as static and access it like you tried to do:

     if (FinishLevel.Level1Complete){