Check if player (rigidbody) not moving for x seconds
I'm working on a script, so I could detect when player is not moving for x seconds and load another scene accordingly.
If player started moving again after x seconds, then loading another scene should't be called.
I've tried using isSleeping function and delay it by including Coroutine with WaitForSeconds but it is still checking regidbody every frame. If there any other way to check if regidbody hasn't moved for x seconds and only then load game over level, otherwise continue moving as before?
using UnityEngine;
using System.Collections;
public class PlayerStop : MonoBehaviour {
void Update() {
if (GetComponent<Rigidbody2D>().IsSleeping()) {
Application.LoadLevel(2);
}
}
}
Shouldn't be easier too check if there's no Input for x second? What is Rigidbody2D Sleep mode set to?
Rigidbody2D mode is set to "Start Awake"
in addition I have a script, which enables me to draw lines and stop player movement, however lines disappear after x seconds. So for example if I set lines to disappear after 1 second I would like to check if Rigidbody2D stopped moving for 2 seconds and only then load game over scene.
Your answer
Follow this Question
Related Questions
Rigidbody sleep disable 0 Answers
Roll a ball- Keys not working 2 Answers
Error CS0103 : The name rb does not exist in the current context 2 Answers