Tondy
New member
- Joined
- Aug 14, 2021
- Messages
- 1
- Programming Experience
- 5-10
Hello,
So I am working on a mini game that dynamically creates quads of 2 * 2 or 2 * 4 or 4 * 4. The player is then prompted to tap on a random neighbouring quad starting from the bottom right. The neighbouring quad needs to be chess move king distance from the current grid point. New neighbouring grid points are prompted through out the game. How could I write code that finds neighbouring quads from a given current quad point?
This is the current code creating grid point :
So I am working on a mini game that dynamically creates quads of 2 * 2 or 2 * 4 or 4 * 4. The player is then prompted to tap on a random neighbouring quad starting from the bottom right. The neighbouring quad needs to be chess move king distance from the current grid point. New neighbouring grid points are prompted through out the game. How could I write code that finds neighbouring quads from a given current quad point?
This is the current code creating grid point :
C#:
public void CreateQuadArray()
{
totalQuads = quadRows * quadColumns;
gridPoints = new Vector3[quadRows, quadColumns];
currentGridPoint = new int[quadRows, quadColumns];
for (int row = 0; row < gridPoints.GetLength(0); row++)
{
gridPoints[row, 0] = new Vector3(quadRowOffSet * row,0,0);
for (int col = 0; col < gridPoints.GetLength(1); col++)
{
gridPoints[row, col] = new Vector3(quadRowOffSet * row, 0, quadColumnOffSet * col);
MakeQuad(gridPoints[row, col]);
}
}
}
public void MakeQuad(Vector3 quadPosition)
{
var Quad = Instantiate(Resources.Load("Prefabs/Quad"), quadPosition, Quaternion.Euler(90,0,0)) as GameObject;
var quadIndex = UnityEngine.Random.Range(0, totalQuads);
Quad.name = stepCountQuads.quads[quadIndex].QuadTitle.ToString();
Quad.GetComponent<QuadController>().QuadID = stepCountQuads.quads[quadIndex].QuadId;
Quad.GetComponent<QuadController>().QuadMaterial = stepCountQuads.quads[quadIndex].QuadMaterial;
}
Last edited by a moderator: