I'd like to get the neighbors of the box by raycasting, but it's working only left and down directions. Could you help me, why is it not getting the neighbors of right and up directions? thanks
All boxes in grid[x,y]:
o - is box.
[-----------]
o o o o
o o o o
o o o o
o o o o
[----------]
...
rLeft = new Ray(this.transform.position, Vector3.left);
rRight = new Ray(transform.position, Vector3.right);
rUp = new Ray(transform.position, Vector3.up);
rDown = new Ray(transform.position, Vector3.down);
GetNeigbor(rUp); // not work
GetNeigbor(rLeft); //worked
GetNeigbor(rRight); //not work
GetNeigbor(rDown); //worked
}
void GetNeigbor(Ray ray)
{
if (Physics.Raycast(ray, out _rayHit, 40) /*&& _rayHit.transform.tag == "MatchBox"*/)
{
neigbors.Add(_rayHit.collider.gameObject);
}
}
From unity docs:
It helped me.
.. ..
http://docs.unity3d.com/ScriptReference/Physics.Raycast.html
You are using Vector3, which is 3D, in a 2D matrix.