public void CreateTree(RiverGridController grid, RiverGridNode parent, int numRows, int numCols)
 {
     this.grid = grid;
     this.parent = parent;
     numChildren = numRows;
     RiverGridNode temp = null;
     children = new RiverGridNode[numChildren];
     float tempZFloat = grid.startZ;
     float tempYFloat = grid.startY;
     Vector3 tempLocation;
     for (int i = 0; i < numChildren; i++){
         temp = (RiverGridNode)ScriptableObject.CreateInstance ("RiverGridNode");
         if (this.parent == null)
         {
             //tempZFloat += grid.zStep;
             // Assume this is a direct child of the root. Update z steps
             tempLocation = new Vector3(location[0],location[1],tempZFloat + i*grid.zStep);
             temp.Init (tempLocation);
         }
         else if (this.parent.parent == null)
         {
             //tempXFloat += grid.xStep;
             // Assume this is a direct child of the root. Update x steps
             tempLocation = new Vector3(location[0],tempYFloat + i*grid.yStep,location[2]);
             temp.Init (tempLocation);
         }
         else
         {
             Debug.LogError ("Impossible case in CreateTree, this RiverGridNode has no parent pointer AND no parent.parent pointer");
         }
         //temp.Init (location);
         temp.CreateTree(grid,this,numCols,0);
         children[i] = temp;
     }
 }
    // Every MonoBehavior has a Start function which is called upon instantiation into the Scene / Hierarchy
    void Start()
    {
        // Set class specific constants
        origin = new Vector3 (0, 0, 0);
        identity = Quaternion.identity;
        InitialVelocity = origin;

        // Initialize the random number generator
        // Use any integer seed value to track your procedural river creation
        seed = new Seed ();
        // Initialize drop pool and living drop counter.
        // Ideally numDropsAvailable will track how many drops have not been processed into rain.
        // This should end up being slightly less than or equal to the current size of the Queue in any given frame.
        availableDrops = new Queue<GameObject>();
        numDropsAvailable = 0;
        // Create the root node of the showerhead tree
        root = (RiverGridNode)ScriptableObject.CreateInstance("RiverGridNode");
        // Give it a base location Vector3 (the center point of the river grid)
        location = new Vector3 (startX, centerY, centerZ);
        root.Init (location);
        // Recursively create the showerhead tree with a pointer to the following objects:
        // This class, a null parent, and the dimensions of the tree.
        root.CreateTree (this, null, numZSteps, numYSteps);
        // Now prime the pump by adding drops to the available drops queue
        StartCoroutine (PopulateDrops());
        // And now start dropping them on a regular timer
        dropping = StartDropping ();
        StartCoroutine (dropping);
        // Implied: Gravity and constant force is included in the drop prefab - River will begin with the instantion of this script.
    }
 public void UpdateRiverTree()
 {
     bool wasOn = on.isOn;
     root.Kill ();
     root = null;
     if (wasOn == true) {
         StopCoroutine (dropping);
         on.isOn = false;
     }
     // Create the root node of the showerhead tree
     root = (RiverGridNode)ScriptableObject.CreateInstance("RiverGridNode");
     // Give it a base location Vector3 (the center point of the river grid)
     location = new Vector3 (startX, centerY, startZ);
     //Debug.LogError ("Creating riverGridNodes at center: " + location [0] + "," + location [1] + "," + location [2]);
     root.Init (location);
     // Recursively create the showerhead tree with a pointer to the following objects:
     // This class, a null parent, and the dimensions of the tree.
     root.CreateTree (this, null, numZSteps, numYSteps);
     if (wasOn == true) {
         on.isOn = true;
     }
 }