- Home /
Question by
Garrett Lynch · Mar 21, 2013 at 10:28 PM ·
terraintexturessplatmap
How do I set a terrain texture or colour from code?
How do I set a terrain texture or colour (the splatmap) from code to a terrain created from code? This is what I have, I see nothing, where am I going wrong?
using UnityEngine;
using System.Collections;
using Utility;
public class test : MonoBehaviour
{
//use this for initialization
void Start ()
{
//create a new terrain data
TerrainData _terrainData = new TerrainData();
//set terrain width, height, length
_terrainData.size = new Vector3(20, 1, 20);
SplatPrototype[] terrainTexture = new SplatPrototype[1];
terrainTexture[0] = new SplatPrototype();
terrainTexture[0].texture = (Texture2D)Resources.Load("Terrain Assets/Terrain Textures/Grass (Hill)");
_terrainData.splatPrototypes = terrainTexture;
//Create a terrain with the set terrain data
GameObject _terrain = Terrain.CreateTerrainGameObject(_terrainData);
}
// Update is called once per frame
void Update () {
}
}
Comment
Your answer
Follow this Question
Related Questions
Terrain Splatmap Optimization - 4 Texture still true? 1 Answer
Terrain in an RTS style game 1 Answer
Convert terrain with trees to image 0 Answers
Copying sections of terrain textures 0 Answers