public void MergeHeads(FlowTileLogic tile) { pathTiles.Add(tile); tile.IsChecked = true; coordinates = tile; ROTATION rot = CountRotationHead(); int mat = ChooseMaterial(); //head coordinates.gameObject.transform.rotation = Quaternion.Euler(RotationFromROTATION(rot)); //rest if (pathTiles.Count >= 2) { pathTiles[pathTiles.Count - 2].GetComponent <SpriteRenderer>().sprite = box.sprites[mat]; if (mat == 2) { rot = CountRotationSecond(); } pathTiles[pathTiles.Count - 2].gameObject.transform.rotation = Quaternion.Euler(RotationFromROTATION(rot)); } FlowGameManager.Instance.CheckIfAllClicked(); pathTiles[0].GetComponent <SpriteRenderer>().sprite = box.sprites[0]; transform.position = pathTiles[0].gameObject.transform.position; coordinates = pathTiles[0]; pathTiles.RemoveAt(pathTiles.Count - 1); }
public void Init(FlowTileLogic tile) { pathTiles.Add(tile); coordinates = pathTiles[0]; coordinates.IsChecked = true; coordinates.GetComponent <SpriteRenderer>().sprite = box.sprites[0]; coordinates.ColorTiler(box.color); }
public void GoBack() { pathTiles[pathTiles.Count - 1].IsChecked = false; pathTiles[pathTiles.Count - 1].GetComponent <SpriteRenderer>().sprite = box.sprites[3]; pathTiles.RemoveAt(pathTiles.Count - 1); coordinates = pathTiles[pathTiles.Count - 1]; gameObject.transform.position = pathTiles[pathTiles.Count - 1].transform.position; ROTATION rot = CountRotationHead(); coordinates.GetComponent <SpriteRenderer>().sprite = box.sprites[1]; coordinates.gameObject.transform.rotation = Quaternion.Euler(RotationFromROTATION(rot)); pathTiles[0].GetComponent <SpriteRenderer>().sprite = box.sprites[0]; coordinates.GetComponent <SpriteRenderer>().sprite = box.sprites[0]; }
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); }
// 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; } }