I have generated grid with specific pattern(controlled grid)…And now i want to make list of all neighbours of perticular cell.
I have created some of the cell with transform and some of them filled with sphere prefab.
When i shoot sphere , i need to check the sphere with same color. And if they are more than 3 then i want to destroy them. But i do not understand the way how to manage neighbours for each cell.
How will i get neighbours of the collided object in shooting script associated with each sphere ??
Pleaze somebody guide me.
Code to generate Grid:
public var sphere : Transform[];
private var B : int = 0;
private var G : int = 1;
private var P : int = 2;
private var R : int = 3;
private var Y : int = 4;
private var E : int = 5;
public var m : int= 12;
public var n : int = 12;
public var radius : float = 0.5f;
public var useAsInnerCircleRadius : boolean = true;
private var offsetX : float;
private var offsetY : float;
private var formation = [ [E ,E ,E ,E, E, E, B, Y, Y ],
[E ,E ,E ,E, E, E, Y, Y, Y ],
[E ,E ,E ,E, E, E, Y, G, G ],
[E ,E ,E ,E, E, E, P, R, G ],
[E ,E ,E ,E, E, E, R, R, R ],
[E ,E ,E ,E, E, E, R, R, R ],
[E ,E ,E ,E, E, E, P, B, B ],
[E ,E ,E ,E, E, E, B, Y, B ],
[E ,E ,E ,E, E, E, G, E, Y ] ];
function Start() {
var go : GameObject = GameObject.Find("Grid");
var unitLengthv : float = ( useAsInnerCircleRadius )? (radius / (Mathf.Sqrt(3)/2)) : radius;
offsetX = Mathf.Sqrt(3);
offsetY = 1.5f;
for(var i : int = 0; i < formation.length; i++ ) {
for(var j : int = 0; j < formation*.length; j++ ) {*
var hexpos : Vector2 = HexOffset( i, j );
var pos : Vector3 = new Vector3( hexpos.x, hexpos.y, 0 ) + transform.position;
var tempsphere : Transform = Instantiate(sphere[formation*[j]], pos, Quaternion.identity );*
tempsphere.transform.parent = go.gameObject.transform;
if(formation*[j] != E)*
{
* tempsphere.transform.rigidbody.constraints = RigidbodyConstraints.FreezeAll;*
}
}
}
}
function HexOffset( x : int, y : int) : Vector2
{
* var position : Vector2 = Vector2.zero;*
* if( y % 2 == 0 ) {*
_ position.x = x ;//* offsetX;
position.y = y ;//* offsetY;
* }
else {
position.x = ( x + 0.5f );// * offsetX;
position.y = y;// * offsetY;
}
return position;
}*
Here E stands for empty space. If the bullet sphere is not collided with same color, then it wil be placed at nearest empty position…
Thanks._
Thanks sir.. But in my shooting script, How can i determine the neighbours of the collided object ? I am very confused. My shooting script is associated with sphere prefab.
– Ekta-Mehta-D