Exemplo n.º 1
0
 public void AddNeighboorIfNotExist(GravityToogleScript neighboor)
 {
     if (!neighboors.Contains(neighboor))
     {
         neighboors.Add(neighboor);
     }
 }
Exemplo n.º 2
0
 public void RemoveNeighboor(GravityToogleScript neighboor)
 {
     if (neighboors.Contains(neighboor))
     {
         neighboors.Remove(neighboor);
     }
 }
Exemplo n.º 3
0
 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);
 }
Exemplo n.º 4
0
    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));
            }
        }
    }