matching corrosponding elements placed in a 2d array
I am making Block'D game and I have placed all the elements in 2D array.Now if I click and on an element, I want to check elements around it on top, bottom, left and right. But if there is a match I have to check for that element too. I tried recursive but that's not my strong area. So anyone can help me using loops, that would be great.
using UnityEngine; using System.Collections; using System.Collections.Generic;
public class box_Delete : MonoBehaviour { int row_index = 0, col_index = 0;
void OnMouseDown()
{
Debug.Log ("Passing it to match_box" + this.tag);
ID_box (gameObject);
}
void match_box()
{
for (int i = 0; i < GridManager.row; i++)
{
for (int j = 0; j < GridManager.col; j++)
{
}
}
}
void ID_box(GameObject obj)
{
for (int i = 0; i < GridManager.row; i++)
{
for (int j = 0; j < GridManager.col; j++)
{
if (GridManager.box_arr [i, j] == obj)
{
row_index = i;
col_index = j;
Debug.Log ("(x,y) = " + row_index + "," + col_index);
return;
}
}
}
}
}
box_arr is the array containing the elements.
Your answer
Follow this Question
Related Questions
Trying to understand target matching 0 Answers
Get the transform.position of a gameobject in an array? 2 Answers
I want to span an array of the same object in a mathematical array, like a lightshow in sequence 0 Answers
Convert a list into a GameObject[] Array,How to convert a list to a gameObject[] 1 Answer
How can i access another scripts GameObject Array to check its inside if there are any tower 1 Answer