Skip to content

Instantly share code, notes, and snippets.

@crilleengvall
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crilleengvall/6e27628b1b09acc9ac23 to your computer and use it in GitHub Desktop.
Save crilleengvall/6e27628b1b09acc9ac23 to your computer and use it in GitHub Desktop.
How to check if a game object has stopped moving
using UnityEngine;
using System.Collections;
public class StuckSheepCheck : MonoBehaviour {
public GameObject Sheep;
public GameObject SheepTwo;
private Rigidbody2D SheepRigidbody2D;
private Rigidbody2D SheepTwoRigidbody2D;
void Start() {
this.SheepRigidbody2D = Sheep.GetComponent<Rigidbody2D>();
this.SheepTwoRigidbody2D = SheepTwo.GetComponent<Rigidbody2D>();
}
void FixedUpdate () {
this.CheckIfSheepIsStuck();
}
private void CheckIfSheepIsStuck() {
if(this.SheepRigidbody2D.IsSleeping() && this.SheepTwoRigidbody2D.IsSleeping()) {
SheepGameEnder.Instance.EndGame();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment