【发布时间】:2018-01-10 05:58:15
【问题描述】:
我试图在一组对象移动一定距离后实例化一个对象。在我的代码中,我正在制作墙壁,我想做的是创建 2 个杆,拖动鼠标并在杆之间创建一堵墙,我有这么多。我想要遵循的是,如果 2 个杆之间的距离超过了第一个墙支撑的位置并添加到索引中,并且在第一个墙和末端杆之间实例化了一个新墙。
void adjustWall()
{
//start and end pole look at each other
startPole.transform.LookAt(endPole.transform.position);
endPole.transform.LookAt(startPole.transform.position);
//gets the distance between the start and end poles
float distance = Vector3.Distance(startPole.transform.position, endPole.transform.position);
//places the wall between the 2 poles, rotates it to face both of them and scales it between them.
wall.transform.position = startPole.transform.position + distance / 2 * startPole.transform.forward;
wall.transform.rotation = endPole.transform.rotation;
//wall.transform.localScale = new Vector3(wall.transform.localScale.x, wall.transform.localScale.y, distance);
if (distance > 10)
{
//if the distance is greater than 10, set wall, add it to an index then instaniate a new wall between that wall and the end poll. Do this Once until it's time to create a new wall.
}
}
adjustWall 在我的更新函数中被调用。
【问题讨论】:
-
这是什么框架? unity3d?
-
您能更具体地说明您的要求吗?当距离大于 10 时,是否要实例化一个新的预制件?
-
是 Unity 3D 并且距离大于 10 我想实例化一个新的预制件。谢谢。
-
以不能超过 10 的增量建造墙怎么样?使用模块化数学,您可以找到所需的 10 长墙的数量,然后用较短的墙填充剩余部分。循环的良好候选者。
-
我没有想到,如果这些墙的尺寸不那么奇怪,我会这样做。