Код: Выделить всё
private void CheckHorizontalMatches(string color)
{
RaycastHit2D hit = Physics2D.Raycast(transform.position, rayDirection, Mathf.Infinity, cubeLayer);
Debug.DrawRay(transform.position, rayDirection * 5f, Color.green); // Draw a green ray to visualize direction
GameObject startCube = null;
int count = 0;
while (hit.collider != null && hit.collider.tag == color && !detectedRedCubes.Contains(hit.collider.gameObject))
{
Debug.Log("Obj Name:" + hit.collider.gameObject);
count++;
startCube = hit.collider.gameObject;
// Check if the collided cube is not "Red" tagged, and if so, break out of the loop
if (hit.collider.tag != "Red")
{
break;
}
startCube.layer = LayerMask.NameToLayer("detectedRedCubesLayer");
detectedRedCubes.Add(startCube); // Add the cube to the list of detected cubes
hit = Physics2D.Raycast(startCube.transform.position, Vector2.right, Mathf.Infinity, cubeLayer & ~(1 = 3 && detectedRedCubes.Count >= 3)
{
}
}
Пока меня устраивает горизонталь. бит кода, в котором он определяет, есть ли 3 или более кубиков красного цвета, поскольку в ряду может быть не более 5 красных кубиков. Настоящая проблема — обнаружить 3 или более синих кубика, сложенных друг на друга.
Подробнее здесь: https://stackoverflow.com/questions/784 ... or-more-bl