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);
}
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,