我有几个预制件用于随机生成“房间”,但相同的代码导致宽度不一致:
顶部(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);
}
我要疯了吗?是不是太晚了,我错过了什么?
谢谢。