I have set my App to go to a ‘screensaver’ scene if it doesn’t detect any touch input for 60 secs.
However, this doesn’t seem to work if the user is typing (in an InputField) with the native keyboard; even if they are typing, it will go to the screensaver scene after 60 secs.
This is my script:
public float timeOut = 30.0f;
private float timeOutTimer = 0.0f;
void Update(){
timeOutTimer += Time.deltaTime;
if (Input.touchCount > 0){
timeOutTimer = 0.0f;
}
if (timeOutTimer > timeOut) {
SceneManager.LoadScene("AttractorScene");
}
}
}
I believe it’s the expected behaviour. Input.TouchCount surely register touches within the game itself. However, the keyboard is not part of Unity, which explains the current behaviour.
I suggest you to have a ResetTimer function you will be able to call from the onValueChange event of the InputField component.
void Update(){
timeOutTimer += Time.deltaTime;
if (Input.touchCount > 0){
ResetTimer();
}
if (timeOutTimer > timeOut) {
SceneManager.LoadScene("AttractorScene");
}
}
}
// Specify this function in the `onEndEdit` event of the InputField component
public void ResetTimer()
{
timeOutTimer = 0.0f;
}