Jump to content
Unity Insider Forum
Sign in to follow this  
chefselber

Terrain heigths setzen

Recommended Posts

Hallo,

ich kann mit Sphere´s Löcher in den Boden schiessen.

 

Diese sollen aber beim Start wieder ausgeglichen werden.

Benutze diesen Code:

   private Terrain boden;
  
    private int heightmapheight;
    private int heightmapwidth;
    private TerrainData terraindata;
    private float[,] heights;
    
    private bool hit = false;
    float x;

    void Start() {
        boden = GetComponent<Terrain>();

        terraindata = boden.terrainData;
        heightmapheight = terraindata.heightmapHeight;
        heightmapwidth = terraindata.heightmapWidth;
        heights = terraindata.GetHeights(0, 0, heightmapwidth, heightmapheight);

        float[,] temp = new float[1, 1];   // [1,1]
        temp[0, 0] = 0.039f;                        // 0.038
       for (int x = 200; x <=250; x++)
            for (int y = 200; y <= 250; y++)
            {
                terraindata.SetHeights(x, y, temp);
                Debug.Log(x+" "+ y);
            }
    
       }
	

Das Spiel braucht schon ne ganze Zeit zum Laden.

Kennt jemand einen anderen Weg?

 

MfG

 

 

Loecher_boden.jpg

Share this post


Link to post
Share on other sites

Wie schon im Link von Zer0 gezeigt. Füll zuerst ein Array

 

// we set each sample of the terrain in the size to the desired height
 for (int i=0; i&lt;size; i++)
     for (int j=0; j&lt;size; j++)
         heights[i,j] = desiredHeight;
 // go raising the terrain slowly
 desiredHeight += Time.deltaTime;

und erst dann setz die Höhen ins Terrain

 

 // set the new height
 terr.terrainData.SetHeights(posXInTerrain-offset,posYInTerrain-offset,heights);

 

Müsste schneller sein...

  • Like 1

Share this post


Link to post
Share on other sites

Hab dir jetzt schnell meine Funktion rausgesucht:

public float[,] resetheights = new float[64, 64];

 

    public void ResetHeights() // FOR TESTING, reset to flat terrain
    {
        int x;
        int z;

        for (z = 0; z < terrain.terrainData.heightmapHeight; z++)
        {
            for (x = 0; x < terrain.terrainData.heightmapWidth; x++)
            {
                resetheights[z, x] = 0;
            }
        }

        terrain.terrainData.SetHeights(0, 0, resetheights);
    }

 

lg

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×