Make a new camera and place it over the terrain.
Make sure it is in orthographic mode
Set the camera.aspect
field to terrainData.size.x / terrainData.size.z
Set the camera.orthographicSize
field to terrainData.size.z/2f
Make sure the camera frame is oriented with the terrain's axes. Something along the lines of cam.transform.LookAt(terrain.GetPosition(), terrain.transform.forward);
will do the trick.
Then, you should be able to create a RenderTexture
with the pixel resolution you'd like (based on this answer by Rafal Wiliński):
int resHeight = 1000;
int resWidth = Mathf.RoundToInt(resHeight * camera.aspect);
RenderTexture rt = new RenderTexture(resWidth, resHeight, 24);
camera.targetTexture = rt; //Create new renderTexture and assign to camera
Texture2D screenShot = new Texture2D(resWidth, resHeight, TextureFormat.RGB24, false); //Create new texture
camera.Render();
RenderTexture.active = rt;
screenShot.ReadPixels(new Rect(0, 0, resWidth, resHeight), 0, 0); //Apply pixels from camera onto Texture2D
camera.targetTexture = null;
RenderTexture.active = null; //Clean
Destroy(rt); //Free memory
then, your terrain would be captured in screenshot