Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Removing Grass?

Discussion in 'Scripting' started by NeilM0, Jan 15, 2011.

  1. NeilM0

    NeilM0

    Joined:
    Mar 31, 2009
    Posts:
    135
  2. NeilM0

    NeilM0

    Joined:
    Mar 31, 2009
    Posts:
    135
    Answered my own question. Here is a rough code snippit:


    DetailPrototype dp = new DetailPrototype();
    dp.prototypeTexture = textures[0].diffuseMap;
    dp.maxHeight = 5f;
    dp.maxWidth = 5f;
    dp.renderMode = DetailRenderMode.Grass;

    // Add grass textures to the list
    DetailPrototype[] dpL = new DetailPrototype[1];
    dpL[0] = dp;
    // dpL[1] = dp;
    mTerrain.terrainData.detailPrototypes = dpL;
    int[,] details = new int[10,5];
    for (int x = 0; x < 9; x += 2)
    {
    details[x, 0] = 1;
    details[x+1, 0] = 0;

    details[x, 4] = 1;
    details[x+1, 4] = 1;
    }

    mTerrain.terrainData.SetDetailLayer(0, 0, 0, details);
    // You should see little bits of grass at 0, 0 on the terrain.
     
  3. vsNetworks

    vsNetworks

    Joined:
    Oct 26, 2012
    Posts:
    2
    This was awesome and totally worked for me for removing grass as a tractor drove over the grass. But now I want to change the texture on the terrain, I have tried a couple of ways using this code to help but I can't get it to work. Anyone have any suggestions?
     
  4. tomaz52

    tomaz52

    Joined:
    Feb 12, 2014
    Posts:
    22
    Can you be more specific about this code??
     
  5. heino-heinrich

    heino-heinrich

    Joined:
    Oct 6, 2014
    Posts:
    1
    Excuse me can you explain this code and how you use this code?
     
  6. djfunkey

    djfunkey

    Joined:
    Jul 16, 2012
    Posts:
    201