How can I access objects or variables from another class in C#

Hi..

I have two C# script called: player.cs and enemy.cs . In my enemy.cs script file I have boolean called "attack". So I want to access that from my player script.

I tried in the following way, but I got error : NullReferenceException: Object reference not set to an instance of an object player.Update () (at Assets/scripts/player.cs:44)

Ok here is my script, please tell me what I was wrong??

player.cs:

public class player : MonoBehaviour
{
 private enemy enemyAI;

public void Awake()
    {
        enemyAI = GetComponent<enemy>();
    }

if(enemyAI.attack==true)
{
// do something
}

}

Thanks in advance...

well obviously your enemyAI reference is null.

enemyAI = GetComponent<enemy>();

That line says get the enemy component on the game object you have the player script on. I'm assuming that's not what you need to do since I doubt you'd have the player and enemy components on the same game object.

Use static keyword http://unity3d.com/support/documentation/ScriptReference/index.Member_Variables_26_Global_Variables.html