- Home /
I am trying to change rows and column to x and z
Ok so my friend gave me some code to debug and it has to do with rows and columns. Basically he wants me to make it layout on the x and z coordinates instead of x and y. I am at a loss and it does'nt change even with the code i currently have right now heres the code. It builds 6 rows and 6 columns and the rows are on the y axis and i want it to be on the z axis please and thankyou for the help
for (int i = 0; i < _numRows; i++) { _tmpList = new List<Transform>(); _nodeStatesList = new List<NodeState>(); // CREATE ROW PARENT just for BEAUTY STRUCTURE of GameObjects GameObject parentGO = new GameObject("ROW_"+i.ToString()); parentGO.transform.parent = _parentTransform; _parentTransforms.Insert(i, parentGO.transform); for (int j = 0; j < _numCols; j++) { GameObject go = GameObject.Instantiate(nodePrefab) as GameObject; go.transform.name = go.transform.name.Replace( "(Clone)", "["+i.ToString()+", "+j.ToString()+"]" ); go.transform.parent = _parentTransforms[i]; go.transform.position = new Vector3( j * go.transform.localScale.x * 1.25f, -i * go.transform.localScale.z * 1.25f, go.transform.position.x ); _tmpList.Insert(j, go.transform); _nodeStatesList.Insert(j, go.GetComponent<NodeState>()); } _gridTransforms.Insert(i, _tmpList); _nodeStatesGrid.Insert(i, _nodeStatesList); } _parentTransform.Translate(new Vector3( (-1) * (_numCols - 1) * 0.5f * nodePrefab.transform.localScale.z * 1.25f, (_numRows - 1) * 0.5f * nodePrefab.transform.localScale.x * 1.25f, 0 ));
Answer by Seregon · Jun 30, 2013 at 01:05 PM
The issue is in lines 12-16 of the code you gave, which should be changed from
go.transform.position = new Vector3(
j * go.transform.localScale.x * 1.25f,
-i * go.transform.localScale.z * 1.25f,
go.transform.position.x
);
to
go.position = new Vector3(
j * go.transform.localScale.x * 1.25f,
go.position.y,
-i * go.transform.localScale.z * 1.25f
);
Hope this helps.
Your answer
Follow this Question
Related Questions
Only Lerp 2 coordinates 0 Answers
Locking object (or animation) to X or Y axis 1 Answer
Move Character Through Z and X Axis Simultaneously 0 Answers
Mose look no limits 1 Answer
Alternative to transform.Translate? 3 Answers