Created
February 1, 2020 19:40
-
-
Save PreyK/b3b0b1d9096bb70007beff56a0381d5c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class ProceduralGrass : MonoBehaviour | |
{ | |
private Terrain terrainToPopulate; | |
public int grassDensity; | |
public int patchDetail; | |
[ContextMenu("Grass")] | |
void Start() | |
{ | |
terrainToPopulate = transform.gameObject.GetComponent<Terrain>(); | |
terrainToPopulate.terrainData.SetDetailResolution(grassDensity, patchDetail); | |
int[,] newMap = new int[grassDensity, grassDensity]; | |
for (int i = 0; i < grassDensity; i++) | |
{ | |
for (int j = 0; j < grassDensity; j++) | |
{ | |
newMap[i, j] = 6; | |
} | |
} | |
terrainToPopulate.terrainData.SetDetailLayer(0, 0, 0, newMap); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment