Search Unity

Problems in land generation with SetPixel () function;

Discussion in 'Editor & General Support' started by Rhyusaky, Jan 22, 2016.

  1. Rhyusaky

    Rhyusaky

    Joined:
    Jan 22, 2016
    Posts:
    25
    Hello, I would like to know how can I generate a ground (not heightmap, land) of pixels with SetPixel function (int, int, color);?
    I already tried, but all I can and fill half of texture in green, the problem yourself and to generate reliefs and mountains, can someone help me?
    That is your current code with problems:
    Code (JavaScript):
    1.  
    2. #pragma strict
    3.  
    4. var Terrain: Texture2D = new Texture2D(100,100);
    5. var Pixel: Color;
    6. var X: float;
    7. var Y: float;
    8. var Perlin: float;
    9. var PerlinFactor: int;
    10. var PerlinI: int;
    11. var Material: Material;
    12. var Seed: float = 0;
    13.  
    14.  
    15. function Start () {
    16. for(X = 0; X < Terrain.height; X++)
    17.    for(Y = 0; Y < Terrain.width; Y++)
    18.    {
    19.    Terrain.SetPixel(X,Y,Color.clear);
    20.    }
    21.    Terrain.Apply();
    22. for(X = 0; X < Terrain.height; X++)
    23.    for(Y = 0; Y < 500; Y++)
    24.    {
    25.    Perlin = PerlinFactor*Mathf.PerlinNoise(Random.Range(0.0,0.5),Random.Range(0.6,1.0));
    26.    PerlinI = Mathf.FloorToInt(Perlin);
    27.    PerlinI = Random.Range(Y+1,Y+100);
    28.    Terrain.SetPixel(X,Y+PerlinI,Pixel);
    29.    }
    30.    Terrain.Apply();
    31.    Material.mainTexture = Terrain;
    32.    print("The Map Has Sucefully Generated!!!");
    33. }
    And then, someone help me?