Skip to content

Instantly share code, notes, and snippets.

@PreyK
Created February 1, 2020 19:40
Show Gist options
  • Save PreyK/b3b0b1d9096bb70007beff56a0381d5c to your computer and use it in GitHub Desktop.
Save PreyK/b3b0b1d9096bb70007beff56a0381d5c to your computer and use it in GitHub Desktop.
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