Hello there, I am currently working on my survival game, I need a little bit of help with procedurally generating my island. Currently, I have a 500x500 terrain gameobject. I have managed to find some code (after 2 hours) that works when amended to my personal use. Here is the code;
using UnityEngine;
using UnityEditor;
using System.Collections;
public class ProceduralGeneration : MonoBehaviour
{
public Terrain terrain;
void generateMap()
{
TerrainData TD = terrain.terrainData;
float[,] HeightMap = new float[TD.heightmapWidth,TD.heightmapHeight];
for(int x=0;x<TD.heightmapWidth;x++)
{
for(int y=0;y<TD.heightmapHeight;y++)
{
HeightMap [x, y] = Random.Range (10, 15);
}
}
TD.SetHeights(0,0,HeightMap);
}
void Start()
{
generateMap();
}
}
However, this code, despite working, works incorrectly.
I apologize that I am unable to help your coding problem, but I saw that you didn’t have a response yet so I thought I would let you know that I had seen a Unity tutorial series on this that I watched for procedurally generating land mass.
They’re 2 and a half hours long, and I know you’d probably have to re-do some stuff but thought maybe it could help you. Have a great and productive day :).
After debugging noiseMap, it apparently returns an empty array, but when used in my other method, returns perfectly fine. Then again, printing the length returns an array with 1000+ values.