【发布时间】:2015-02-26 08:31:43
【问题描述】:
我有几个预制件用于随机生成“房间”,但相同的代码会导致宽度不一致:
顶部(northWall)的宽度应该与底部(southWall)的宽度相同,但显然是 3 倍。
这是实例化其他“墙”预制件的“房间”预制件(此时它们基本上都只是四边形)。
public float length;
public float width;
public float wallDepth;
public Transform northWall;
public Transform southWall;
void Start () {
length = Random.Range (5.0f, 25.0f);
width = Random.Range (5.0f, 25.0f);
wallDepth = 2.0f;
transform.localScale = new Vector3 (width, length, 0.0f);
Instantiate (northWall, new Vector3(transform.localPosition.x, transform.localPosition.y + (transform.localScale.y / 2) + (wallDepth / 2), 10.0f), Quaternion.identity);
northWall.transform.localScale = new Vector3 (width, wallDepth, 10.0f);
Instantiate (southWall, new Vector3(transform.localPosition.x, transform.localPosition.y - (transform.localScale.y / 2) - (wallDepth / 2), 10.0f), Quaternion.identity);
southWall.transform.localScale = new Vector3 (width, wallDepth, 10.0f);
}
我要疯了吗?是不是太晚了,我错过了什么?
谢谢。
【问题讨论】:
-
你在inspector中设置了什么northwall和southwall?
-
我刚刚为每个人拖了一个墙预制件。 Wall 是一个带有盒子碰撞器的四边形。
-
那么inspector里面的规格是什么?
-
它们没有规格,它们是默认四边形,其位置和比例设置为相同的随机浮点数(根据上面的代码)。但正如您所见,南墙是正确的,北墙不是。它们是完全相同的预制件。