public void AddNeighboorIfNotExist(GravityToogleScript neighboor) { if (!neighboors.Contains(neighboor)) { neighboors.Add(neighboor); } }
public void RemoveNeighboor(GravityToogleScript neighboor) { if (neighboors.Contains(neighboor)) { neighboors.Remove(neighboor); } }
public bool GravityCheck(GravityToogleScript caller = null) { // checks if the gravity should be enabled, reccursively... Debug.Log("GravityCheck on cube " + id); if (isParentNeighboor || transform.localPosition.y == 0) { Debug.Log("Cube " + id + " is grounded"); return(false); } foreach (var n in neighboors) { if (n != caller && !n.GravityCheck(this)) { Debug.Log("Cube " + id + " not in the air"); return(false); } } Debug.Log("activating gravity"); rigidbody.useGravity = true; StartCoroutine(DestroyIfNotMovingAfterCollapse(this)); return(true); }
IEnumerator DestroyIfNotMovingAfterCollapse(GravityToogleScript cube) { Vector3 lastPos = cube.transform.position; yield return(new WaitForSeconds(0.1f)); bool b = true; while (b) { if (lastPos == cube.transform.position) { cube.HandleFloorCollision(); b = false; } else { lastPos = cube.transform.position; yield return(new WaitForSeconds(0.1f)); } } }