// private void Start() // { // coordinates.IsChecked = true; // coordinates.GetComponent<Renderer>().sharedMaterial = materials[1]; // } // private void Update() // { // } public void Move(TailsTileLogic tile) { pathTiles.Add(tile); tile.IsChecked = true; coordinates = tile; gameObject.transform.position = tile.transform.position; ROTATION rot = CountRotationHead(); int mat = ChooseMaterial(); //head coordinates.GetComponent <Renderer>().sharedMaterial = materials[1]; coordinates.gameObject.transform.rotation = Quaternion.Euler(RotationFromROTATION(rot)); //rest if (pathTiles.Count >= 2) { pathTiles[pathTiles.Count - 2].GetComponent <Renderer>().sharedMaterial = materials[mat]; if (mat == 2) { rot = CountRotationSecond(); } pathTiles[pathTiles.Count - 2].gameObject.transform.rotation = Quaternion.Euler(RotationFromROTATION(rot)); } box.SubMoves(); TailsGameManager.Instance.CheckIfAllClicked(); }
public void Init(TailsTileLogic tile) { pathTiles = new List <TailsTileLogic>(); pathTiles.Add(tile); coordinates = pathTiles[0]; coordinates.IsChecked = true; coordinates.GetComponent <Renderer>().sharedMaterial = materials[1]; }
public void GoBack() { pathTiles[pathTiles.Count - 1].IsChecked = false; pathTiles[pathTiles.Count - 1].GetComponent <Renderer>().sharedMaterial = materials[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 <Renderer>().sharedMaterial = materials[1]; coordinates.gameObject.transform.rotation = Quaternion.Euler(RotationFromROTATION(rot)); box.AddMoves(); }
// 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); if (hit != null && hit.Length > 0) { int iterator = 0; while (!found) { head = hit[iterator].collider.gameObject.GetComponent <TailsHeadController>(); iterator++; if (head != null || iterator >= hit.Length) { found = true; } } } } if (Input.GetMouseButton(0)) { if (head != null) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit[] hit2 = Physics.RaycastAll(ray); TailsTileLogic tile = null; if (hit2 != null && hit2.Length > 0) { bool found = false; int iterator = 0; while (!found) { tile = hit2[iterator].collider.gameObject.GetComponent <TailsTileLogic>(); 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.pathTiles.Count > 1) { if (head.pathTiles[head.pathTiles.Count - 2] == tile) { head.GoBack(); } } } else if (head.box.moves > 0) { if (head.pathTiles.Count <= 1) { if (head.box.IsExitAvailable(tile.X - head.coordinates.X, tile.Y - head.coordinates.Y)) { head.Move(tile); } } else { head.Move(tile); } } } } } } } if (Input.GetMouseButtonUp(0)) { head = null; } }