Exemplo n.º 1
0
 // Use this for initialization
 void Start()
 {
     gc = gameObject.GetComponent <GroundClick>();
 }
Exemplo n.º 2
0
 void Start()
 {
     Gclick = GO.GetComponent <GroundClick>();
 }
Exemplo n.º 3
0
    // Use this for initialization
    void Start()
    {
        Random.seed = seed;
        Terrain     trn = terrain.GetComponent <Terrain>();
        TerrainData td  = trn.terrainData;

        //length = td.heightmapWidth;
        //width = td.heightmapHeight;
        float[,] hm = new float[length, width];
        heights     = new int[length, width];

        int max  = minHeight;
        int min  = maxHeight;
        int maxX = 0;
        int maxY = 0;



        for (i = 0; i < width; ++i)
        {
            for (j = 0; j < length; ++j)
            {
                int height = 0;
                if (generatorType != GeneratorType.perlin)
                {
                    if (i == 0)
                    {
                        if (j == 0)
                        {
                            height = randInRange(minHeight, maxHeight, GeneratorType.simple);
                        }
                        else
                        {
                            int prevH = heights[i, j - 1];
                            height = prevH + randInRange(-localDelta, localDelta);
                            height = Mathf.Clamp(height, minHeight, maxHeight);
                        }
                    }
                    else
                    {
                        if (j == 0)
                        {
                            int prevH = heights[i - 1, j];
                            height = prevH + randInRange(-localDelta, localDelta);
                            height = Mathf.Clamp(height, minHeight, maxHeight);
                        }
                        else
                        {
                            int a  = heights[i, j - 1];
                            int a1 = a - localDelta;
                            int a2 = a + localDelta;
                            int b  = heights[i - 1, j];
                            int b1 = b - localDelta;
                            int b2 = b + localDelta;

                            int left  = System.Math.Max(a1, b1);
                            int right = System.Math.Min(a2, b2);

                            //int left = System.Math.Min(a1, b1);
                            //int right = System.Math.Max(a2, b2);

                            if (left <= right)
                            {
                                height = randInRange(left, right);
                                height = Mathf.Clamp(height, minHeight, maxHeight);
                            }
                            else
                            {
                                height = (heights[i, j - 1] + heights[i - 1, j] +
                                          2 * randInRange(-localDelta, localDelta)) / 2;
                                height = System.Math.Max(height, minHeight);
                                height = System.Math.Min(height, maxHeight);
                                Debug.Log("bad range");
                            }
                        }
                    }
                }
                else
                {
                    height = randInRange(minHeight, maxHeight);
                }

                if (height > max)
                {
                    max  = height;
                    maxX = i;
                    maxY = j;
                }
                if (height < min)
                {
                    min = height;
                }

                heights[i, j] = height;
                hm[i, j]      = toY(height) * terrainHeightScale;

                Transform grc
                    = (Transform)Instantiate(
                          groundCube,
                          new Vector3(
                              toX(j),
                              toY(height) / 2f,
                              toZ(i)),
                          Quaternion.identity);

                grc.localScale = new Vector3(
                    grc.localScale.x
                    , toY(height),
                    grc.localScale.z);

                GroundClick cmpt = grc.GetComponent <GroundClick>();
                cmpt.i = i;
                cmpt.j = j;
            }
        }
        td.SetHeights(0, 0, hm);

        int height0 = (max + min) / 2;

        Instantiate(
            waterPlane,
            new Vector3(
                toX(length / 2),
                toY(height0),
                toZ(width / 2)),
            Quaternion.identity);
    }