- Home /
Question by
makeshiftwings · May 27, 2011 at 05:09 AM ·
textureterrainterraintoolkit
TerrainToolkit API - TextureTerrain doesn't work in full build
Hi, I'm trying to create and texture a terrain at runtime using the TerrainToolkit API. If I use the script below and hit play in the Unity editor, the texturing seems to work fine, but when I build and run a Windows executable, the terrain gets generated but it's entirely white, no textures. What am I doing wrong?
void Start()
{
var terrain = GameObject.Find("Terrain");
var toolkit = terrain.GetComponent("TerrainToolkit") as TerrainToolkit;
toolkit.PerlinGenerator(2, .5f, 9, 1);
var cliffTexture = (Texture2D)Resources.LoadAssetAtPath("Assets/Standard Assets/Terrain Assets/Terrain Textures/Cliff (Layered Rock).psd", typeof(Texture2D));
var sandTexture = (Texture2D)Resources.LoadAssetAtPath("Assets/Standard Assets/Terrain Assets/Terrain Textures/GoodDirt.psd", typeof(Texture2D));
var grassTexture = (Texture2D)Resources.LoadAssetAtPath("Assets/Standard Assets/Terrain Assets/Terrain Textures/Grass (Hill).psd", typeof(Texture2D));
var rockTexture = (Texture2D)Resources.LoadAssetAtPath("Assets/Standard Assets/Terrain Assets/Terrain Textures/Grass&Rock.psd", typeof(Texture2D));
var slopeStops = new float[] { 20.0f, 50.0f };
var heightStops = new float[] { .2f, .4f, .6f, .8f };
var textures = new Texture2D[] { cliffTexture, sandTexture, grassTexture, rockTexture };
toolkit.TextureTerrain(slopeStops, heightStops, textures);
}
Comment
Answer by Amotea · Aug 12, 2011 at 11:53 AM
Resources.LoadAssetAtPath doesn't work outside of the editor: http://unity3d.com/support/documentation/ScriptReference/Resources.LoadAssetAtPath.html
Use Resources.Load instead: http://unity3d.com/support/documentation/ScriptReference/Resources.Load.html