(C#) If statements based on variables in another script

Hello, I have a script called “enemyscript” where an if statement is based on the status of a boolean in another script, but it’s not quite working right. I have a script called “movement” that contains the boolean variable called “isAttacking”. The idea is that once the player hits the trigger, if the variable is true, I want the object the enemyscript is attatched to to be destroyed, but if the variable is false, I want the current scene to be reloaded. Here is the enemyscript:

using UnityEngine;
using System.Collections;

public class enemyscript : MonoBehaviour {

	void OnTriggerEnter(Collider other) {		
		if(other.name == "Player"){
		
			if(other.gameObject.GetComponent<movement>().isAttacking == true){
		
				Destroy(this.gameObject); 
		}
		else
		{
			Application.LoadLevel(Application.loadedLevel);	
		}
		}	
	}
}

and here is the script containing the boolean I’m trying to check (only the top part is relevant to this, but I’m posting the whole thing for the sake of completeness):

using UnityEngine;
using System.Collections;
public class movement : MonoBehaviour {

	public float speed = 6.0F;
	public float jumpHeight = 8.0F;
	public float gravity = 20.0F;
	public bool isAttacking = true;
	private Vector3 moveDirection = Vector3.zero;
	CharacterController controller;
	

	void Start(){
controller = GetComponent<CharacterController>();
}
	void Update() {					
		if (controller.isGrounded) {
			  moveDirection = Vector3.forward;
			  moveDirection = transform.TransformDirection(moveDirection);
			  moveDirection *= speed;		
			  

			if (Input.GetButtonDown("Jump"))
			{
				moveDirection.y = jumpHeight;
			}			
	
		}       
		moveDirection.y -= gravity * Time.deltaTime;
		controller.Move(moveDirection * Time.deltaTime);
	}
}

My problem is that the game object on which the enemyscript is attatched to is being destroyed regardless of the state of the isAttacking variable. Even if I change isAttacking to false in the movement script, it’s being destroyed as opposed to reloading the scene. What should I do to fix this?

Rather access properties in your classes like this…
It makes for cleaner code, and always works without the inspector intefering…

[HideInInspector]
public bool IsAttacking { get { return _isAttacking; } set { _isAttacking = value; } }
bool _isAttacking = false;

Then just access the IsAttacking property like…

if(other.IsAttacking)
   Debug.Log("Is Attacking");

And if you want a variable to be in the inspector, but you don’t it to be public, then use the SerializeField attribute…

[SerializeField]
bool IsAttacking = false;