unity3d教程动态创建简单平面地形

unity3d创建地形是不须要usingUnityEditor的。这里使用了AssetDatabase。所以需using UnityEditor;

创建三步:

1.TerrainData

terrainData = newTerrainData();

2.设置terrainData的属性

3.依据terrainData创建地形

  GameObject obj =Terrain.CreateTerrainGameObject(terrainData);

详细脚本例如以下:

using UnityEngine;

using System.Collections;

using UnityEditor;



public class Tutor_1_CreateSimpleTerrain : MonoBehaviour {

void Start()

{

CreateTerrain();

}

public Terrain CreateTerrain()

{

TerrainData  terrainData = newTerrainData();

terrainData.heightmapResolution = 513;

terrainData.baseMapResolution = 513;

terrainData.size = new Vector3(50, 50, 50);

terrainData.alphamapResolution = 512;

    terrainData.SetDetailResolution(32, 8);

GameObject obj =Terrain.CreateTerrainGameObject(terrainData);

AssetDatabase.CreateAsset(terrainData,"Assets/Tutorial/Tutor_1_SimpleTerrain.asset");

    AssetDatabase.SaveAssets();

return obj.GetComponent<</span>Terrain>();

}

}
上一篇:Dynamic Binding & Static Binding


下一篇:11. Container With Most Water