Example #1
0
 public void addBranchesToTree()
 {
     for (int i = tree.Count - 1; i >= 0; i--)
     {
         GameObject oldBranch = (GameObject)tree[i];
         branchScript = oldBranch.GetComponent <BranchScript>();
         if (!branchScript.hasBeenBranched)
         {
             for (int j = 0; j < Random.Range(3, 6); j++)
             {
                 GameObject newBranch = branchScript.createNewBranch(levelCounter, branchCounter);
                 newBranch.transform.SetParent(t);
                 tree.Add(newBranch);
                 branchCounter++;
             }
             branchScript.setHasBeenBranchedToTrue();
         }
         else
         {
             break;
         }
     }
     levelCounter++;
     branchCounter = 0;
 }
Example #2
0
    private void createNewBush(GameObject branch, BranchScript givenBranchScript, int randomBushColor)
    {
        Vector3    spawnPos = branchScript.endPoint.transform.position;
        GameObject newBush  = Instantiate(bushPrefab, spawnPos, Quaternion.identity);

        newBush.transform.localScale = newBush.transform.localScale * Random.Range(0.1f, 1f);
        newBush.transform.parent     = branch.transform;
        if (useOnlyTheColorBelow)         // if useOnlyTheColorBelow == true
        {
            randomBushColor = colorIndexInArray;
        }
        else if (!useSingleRandomColor)         // if useSingleRandomColor == false
        {
            /*
             * Here bushColors.Count gives a number greater than the size of the array
             * but since Random.Range never reaches bushColors.Count (but it does get close in terms of decimals)
             * and since type casting into int truncates the decimals, it looks at all elements in the array.
             */
            randomBushColor = (int)Random.Range(0, bushColors.Count);
        }
        newBush.GetComponent <Renderer>().material = bushColors[randomBushColor];
        branchScript.setHasBeenBranchedToTrue();
    }