Why is my variable always true?

This script is a random encounter script I’ve been working on, everything is working as i expected aside from one slight problem. My “InBattle” bool is always true and i can’t understand why. I only have one spot where it is even allowed to return true, but that is after certain numerical conditions are met. Maybe someone on here could shine some light on this irritation. (:

using System.Collections;

public class BattleSystem : MonoBehaviour {
public  bool InBattle = false;	
private int RandNum;
public int RangeStart = 1;
public int RangeEnd = 4000;
private bool Encounter = false;
public int EncounterRangeStart = 400;	
public int EncounterRangeEnd = 600;	
public float SecondsWalking;
public float StartWalking;
	//for player location/rotation on load
public string AfterBattleMap; 	
public Vector3 AfterBattleLocation;
public Quaternion AfterBattleRotation;	

void Awake () {
		  Application.targetFrameRate = 30;
	// Use this for initialization
void Start () {
// Update is called once per frame
	//This is used to initiate the random battles.
void Update () {
		//initialize RandNum with a random number 1-1000
    RandNum = Random.Range(RangeStart, RangeEnd);
		//keep track of when the player started walking
	if(Input.GetKeyDown(KeyCode.W)||Input.GetKeyDown (KeyCode.S)||Input.GetKeyDown(KeyCode.A)||Input.GetKeyDown (KeyCode.D)){
		StartWalking = Time.time;	
		//add the difference of when the player started walking and when the player stopped walking
	if(Input.GetKeyUp(KeyCode.W)||Input.GetKeyUp (KeyCode.S)||Input.GetKeyUp(KeyCode.A)||Input.GetKeyUp (KeyCode.D)){
	//get forward and back movement and check for battle conditions, also increment time walkin	
    	if (Input.GetKey(KeyCode.W)||Input.GetKey(KeyCode.S)){
				if(Mathf.Round (Time.time)%10==0){ 
				Encounter = true;
			//Random battle conditions, ir Rand is greater than 4 but less than 10 start a battle,
			//and if RandNum is greater than 400 but less than 600 start a battle.
				//reset encounter chance
						Encounter = false;
						if(RandNum > EncounterRangeStart && RandNum < EncounterRangeEnd){  
							InBattle = true;
							StartBattle ();
void StartBattle () {
		Debug.Log ("StartBattle");
		//caches the map the player was on.
		AfterBattleMap = Application.loadedLevelName;
		//caches the Player's location & rotation.
		AfterBattleLocation = GameObject.FindGameObjectWithTag("Player").transform.position;
		AfterBattleRotation = GameObject.FindGameObjectWithTag("Player").transform.rotation;
void EndBattle()
		Debug.Log ("EndBattle");
				if(GameObject.FindGameObjectWithTag("Player")== null)
void OnLevelWasLoaded()
		if(GameObject.FindGameObjectWithTag("Player")!= null)
				GameObject.FindGameObjectWithTag("Player").transform.position = AfterBattleLocation;
				GameObject.FindGameObjectWithTag("Player").transform.rotation = AfterBattleRotation;

if(InBattle=false) needs to be if(InBattle==false) (or, if you prefer, if(!InBattle))

if(InBattle=true) needs to be if(InBattle==true) (or, if you prefer, if(InBattle))