【问题标题】:unity3d - how to create a terrain from a c# scriptunity3d - 如何从 C# 脚本创建地形
【发布时间】:2014-01-22 09:09:01
【问题描述】:

我希望仅使用脚本(最好是 c#)而不是编辑器上的菜单选项来统一创建一块地形。到目前为止,我只有下面的这段代码,但我不知道下一步该怎么做才能让它出现在现场,有人可以帮忙吗?

谢谢

using UnityEngine;
using System.Collections;

public class terraintest : MonoBehaviour {

    // Use this for initialization
    void Start () {
        GameObject terrain = new GameObject();
        TerrainData _terraindata = new TerrainData();
        terrain = Terrain.CreateTerrainGameObject(_terraindata);


    }

    // Update is called once per frame
    void Update () {

    }
} 

【问题讨论】:

    标签: c# unity3d


    【解决方案1】:

    只需添加:

    Vector3 position = ... //the ingame position you want your terrain at
    GameObject ingameTerrainGameObject = Instantiate(terrain, position, Quaternion.identity);
    

    应该使地形出现在游戏中。 Instantiate 方法返回对在游戏中生成的游戏对象的引用,因此如果您以后想要访问它,可以使用该引用。

    【讨论】:

      猜你喜欢
      • 2017-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-26
      相关资源
      最近更新 更多