Looping InvokeRepeating

Hi all

I need help whit looping InvokeRepeating. So i wrote code which loads level when there is no key pres, touch on screen or joystick moment. The problem is this code works only once because by key-pres invoke is canceled, but i need to make it work after every 20 seck. What cold be the solution to this problem? Or beter way to do it?

InvokeRepeating("ielade3", 20,0.1);
var levels2: String;

var axes = new float[9];
function Awake()
{
	Application.targetFrameRate = 300;
}

function Update (){

if(Input.anyKeyDown||EventType.MouseDown   ){
CancelInvoke();
}

for (var i = 1; i <9; i++) {
		var position = Input.GetAxis("Axis" + i);
		if (axes[i] != position) {
			axes[i] = position;
			
		}
		if(axes[i] >0.003||axes[i] <-0.003){
		CancelInvoke();

}
}



for (var evt : iPhoneTouch in iPhoneInput.touches)
{
if (evt.phase == iPhoneTouchPhase.Began)
{
CancelInvoke();


}
}
if (iPhoneInput.touchCount == 1){
CancelInvoke();

	
}
}

function ielade3(){
Application.LoadLevel(levels2);

}

Use a boolean, and instead of cancelling invoke check if a Key was pressed and then reset the boolean.

InvokeRepeating("ielade3", 20,0.1);
var levels2: String;
var keyWasPressed: Boolean = false;

var axes = new float[9];
function Awake()
{
	Application.targetFrameRate = 300;
}

function Update (){

if(Input.anyKeyDown||EventType.MouseDown   ){
keyWasPressed = true;
}

for (var i = 1; i <9; i++) {
		var position = Input.GetAxis("Axis" + i);
		if (axes[i] != position) {
			axes[i] = position;
			
		}
		if(axes[i] >0.003||axes[i] <-0.003){
		keyWasPressed = true;

}
}



for (var evt : iPhoneTouch in iPhoneInput.touches)
{
if (evt.phase == iPhoneTouchPhase.Began)
{
keyWasPressed = true;


}
}
if (iPhoneInput.touchCount == 1){
keyWasPressed = true;

	
}
}


function ielade3(){
if(!keyWasPressed)
{
Application.LoadLevel(levels2);
}
keyWasPressed = false;
}

I don’t code in JS so there is likely syntax issues but I hope that shows the general concept.

tnx works great :slight_smile:

hemm at first i was thinking it works fine, but after some testing i see that level still is loaded, even when i press something all the time.
Ah i saw my mistake invoke was set to 0.1 but it needs to be set to 20. works fine now,