【问题标题】:Having trouble getting C# code to stack a tower. How can I modify this to get it working more like Jenga?无法让 C# 代码堆叠塔。我该如何修改它以使其更像 Jenga 一样工作?
【发布时间】:2014-01-16 01:43:09
【问题描述】:

我正在尝试在 Unity3D 中构建一个堆叠塔,每次添加新关卡时关卡都会改变方向。到目前为止,我已经让它部分工作了 - 在奇数上,方向切换,但我无法得到正确的偏移量。这会导致塔容易爆炸。

void buildTower() {

    int counter = 0;

    for (int y = 0; y < gridY; y++) {
        for (int x = 0; x < gridX; x++) {
            Vector3 pos;
            Quaternion rot = Quaternion.identity;

            Vector3 rotEuler;

            //rotEuler = new Vector3(270, 0, 0);
            //pos = new Vector3(x, y, 0) * spacing;

            if (y % 2 != 0) {
                rotEuler = new Vector3(270, 0, 0);
                pos = new Vector3(x, y, 0) * spacing;
            } else {
                rotEuler = new Vector3(270, 270, 0);
                pos = new Vector3(x, y, 0) * spacing;
            }

            rot.eulerAngles = rotEuler;

            GameObject plank = Instantiate(plankObject) as GameObject;

            plank.transform.parent = Tower.transform;

            plankObject.transform.rotation = rot;
            plankObject.transform.position = pos;

        }
    }
}

【问题讨论】:

    标签: c# unity3d game-engine


    【解决方案1】:

    你的间距变量需要比你的块的高度大一点,这应该有助于它很好地组合在一起。

    【讨论】:

    • 当木板转动时,位置是否还需要从零开始偏移?
    • 是的,在偏航轴上,理想情况下你的预制位置应该从你的积木堆的中心定位
    猜你喜欢
    • 1970-01-01
    • 2010-11-08
    • 2021-08-12
    • 2016-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-13
    • 2019-05-24
    相关资源
    最近更新 更多