public bool IsTileWithSecondHea(FlowHeadController head, FlowTileLogic tile) { if (head == head1) { if (head2.coordinates == tile) { return(true); } } else { if (head1.coordinates == tile) { return(true); } } return(false); }
public void ErasePathFromAnotherHead(FlowHeadController head) { if (isFinished) { head1.ErasePath(); head2.ErasePath(); } else { if (head == head1) { head2.ErasePath(); } else { head1.ErasePath(); } } isFinished = false; }
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { bool found = false; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); //RaycastHit[] hit = Physics.RaycastAll(ray); RaycastHit2D[] hit = Physics2D.GetRayIntersectionAll(ray, 100); if (hit != null && hit.Length > 0) { int iterator = 0; while (!found) { head = hit[iterator].collider.gameObject.GetComponent <FlowHeadController>(); iterator++; if (head != null || iterator >= hit.Length) { found = true; } } } if (head != null) { head.box.ErasePathFromAnotherHead(head); } else { found = false; FlowTail tail = null; if (hit != null && hit.Length > 0) { int iterator = 0; while (!found) { tail = hit[iterator].collider.gameObject.GetComponent <FlowTail>(); iterator++; if (tail != null || iterator >= hit.Length) { found = true; } } } if (tail != null) { tail.head.ErasePath(); head = tail.head; } } } if (Input.GetMouseButton(0)) { if (head != null) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit2D[] hit2 = Physics2D.GetRayIntersectionAll(ray, 100); FlowTileLogic tile = null; if (hit2 != null && hit2.Length > 0) { bool found = false; int iterator = 0; while (!found) { tile = hit2[iterator].collider.gameObject.GetComponent <FlowTileLogic>(); iterator++; if (tile != null || iterator >= hit2.Length) { found = true; } } if (tile != null) { if (CheckIfNeighbours(tile.X, head.coordinates.X, tile.Y, head.coordinates.Y)) { if (tile.IsChecked) { if (head.box.IsTileWithSecondHea(head, tile)) { head.box.isFinished = true; head.MergeHeads(tile); head = null; } else if (head.pathTiles.Count > 1) { if (head.pathTiles[head.pathTiles.Count - 2] == tile) { head.GoBack(); } } } else { head.Move(tile); } } } } } } if (Input.GetMouseButtonUp(0)) { head = null; } }