Example #1
0
    void generateTree()
    {
        float      gs    = JoelHelperMethods.RandomRange(SizeRange.x, SizeRange.y);
        GameObject trunk = (GameObject)Instantiate(TrunkPrefab, Vector3.zero, Quaternion.identity);

        trunk.transform.SetParent(this.transform, false);

        float trunkWidth = gs * JoelHelperMethods.RandomRange(.5f, .8f);

        trunk.transform.localScale = new Vector3(trunkWidth,
                                                 gs * JoelHelperMethods.RandomRange(TrunkHeightRange.x, TrunkHeightRange.y),
                                                 trunkWidth);
        trunk.transform.localPosition = new Vector3(0, trunk.transform.localScale.y / 2, 0);
        int leafCount = (int)JoelHelperMethods.RandomRange(LeafCountRange.x, LeafCountRange.y);

        for (int i = 0; i < leafCount; i++)
        {
            GameObject leafPrefab = LeafPrefabs[(int)JoelHelperMethods.RandomRange(0, LeafPrefabs.Length)];
            GameObject leaf       = (GameObject)Instantiate(leafPrefab, Vector3.zero, Quaternion.identity);
            leaf.transform.SetParent(this.transform, false);
            leaf.transform.localScale = new Vector3(gs * JoelHelperMethods.RandomRange(LeafSizeRange.x, LeafSizeRange.y),
                                                    gs * JoelHelperMethods.RandomRange(LeafSizeRange.x, LeafSizeRange.y),
                                                    gs * JoelHelperMethods.RandomRange(LeafSizeRange.x, LeafSizeRange.y));
            leaf.transform.localPosition = UnityEngine.Random.insideUnitSphere * JoelHelperMethods.RandomRange(LeafPosRadiusRange.x, LeafPosRadiusRange.y);
            leaf.transform.localPosition = new Vector3(leaf.transform.localPosition.x,
                                                       leaf.transform.localPosition.y + trunk.transform.localScale.y,
                                                       leaf.transform.localPosition.z);
            //leaf.transform.Rotate(new Vector3(0, randomRange(0, 180), 0));
        }
    }
Example #2
0
 // Use this for initialization
 void Start()
 {
     for (int i = 0; i < CountWidth; i++)
     {
         for (int j = 0; j < CountLength; j++)
         {
             Vector3 pos = new Vector3(i * gridUnitSize + JoelHelperMethods.RandomRange(0, randomizePosition.x),
                                       JoelHelperMethods.RandomRange(0, randomizePosition.y),
                                       j * gridUnitSize + JoelHelperMethods.RandomRange(0, randomizePosition.z));
             GameObject go = (GameObject)Instantiate(prefab, pos, Quaternion.identity);
             go.transform.SetParent(this.transform, false);
         }
     }
     GetComponent <MeshRenderer>().enabled = false;
 }