我正在尝试通过代码更改父变换来组织层次结构中的某些变换。我有这个功能:
private GameObject[,] SpawnCullingGroups(GameObject[,] cG)
{
for(int i = 0; i < cG.GetLength(0); i++)
{
for (int j = 0; j < cG.GetLength(1); j++)
{
GameObject c = Instantiate(Culler, new Vector3(i * 32f,0,j * 32f), Quaternion.identity) as GameObject;
c.name = "CoullingGroup";
cG[i,j] = c;
foreach (Transform child in GameObject.Find("MapContainer").transform)
{
if (child.position.x >= c.transform.position.x && child.position.x <= (c.transform.position.x + 32)
&& child.position.z >= c.transform.position.z && child.position.z <= c.transform.position.z + 32) {
child.parent = cG [i, j].transform;
}
}
}
}
return cG;
}
有时if条件触发并将其更改为父级,但是通过某些转换它不会起作用。 我最终得到了一些奇怪的模式:
所有扇区(10 * 10)都应为绿色(该区域中CoullingGroup的子级)。 网格是完美的,意味着每个块长3.2个单位,宽3.2个,在x和z轴上分开3.2个单位。
那些不是CullingGroup孩子的人处于条件范围内。 我错过了什么吗?
答案 0 :(得分:2)
With the help of @andeart we solved this by changing the loop into this:
foreach (Transform child in (function(init, $, runner) {
init();
$('#test').addEventListener('click', runner)
})(
function init() {
mocha.setup('bdd');
describe('test at ' + new Date().getTime(), function() {
it('should add 1 + 1', function() {
chai.assert(1 + 1 === 2, 'added 1 + 1');
});
});
},
function $(sel) {
return document.querySelector(sel);
},
function specRunner(e) {
mocha.run();
}
)
We also added another piece of code to avoid MapContainer be deleted.
GameObject.Find("MapContainer").GetComponentsInChildren<Transform>())