Help with invokeRepeating, it wont work for me?

public class RandomEncounters : MonoBehaviour {

public int dangerCounter = 0;
public int dangerLevel = 16;
public int startBattleCounter = 0;
public bool randomEncountersEnabled = true;
public bool encounterZone = true;
public bool startBattle = false;

// Use this for initialization
void Start () 
{

	startBattleCounter = UnityEngine.Random.Range( 0, 255 );

}

// Update is called once per frame
void Update () 
{

	if ( randomEncountersEnabled == true && encounterZone == true ) 
	{
		
		RandomEncountersEnabled();
		Debug.Log ( dangerCounter );
		randomEncountersEnabled = false;
	}

}

public void BattleCountDown () 
{

	dangerCounter += ( 4096 / dangerLevel );

	Debug.Log("yay");
	
}

public void RandomEncountersEnabled () 
{
	InvokeRepeating("BattleCountDown", 0, 0.4f);

	do 
	{

		Debug.Log(dangerCounter);

	} while ( dangerCounter / 256 < startBattleCounter );

	randomEncountersEnabled = false;

	CancelInvoke ( "BattleCountDown" );
}

}

I cant get this to work, it just makes unity crash. I want to be able to start BattleCountDown on command and stop it when I want.

Thanks!

It looks like your issue is not actually because of the Invokerepeating, thats oky, the reason it crashes is probably because it enters an infinite loop in your do/while. There is nothing else going on in that same frame that would change the value so the loop could be exited.