public bool CheckNeighbors() { int isPopulated = 0; int isValid = 0; Vector3 cubePosition = HexMath.AxialToCube(HexMath.PixelToHex(transform.position)); RaycastHit hit; int direction; for (int i = 0; i < 6; i++) { if (Physics.Raycast(HexMath.HexToPixel(HexMath.CubeToAxial(cubePosition + HexMath.direction[i])) + Vector3.forward, Vector3.back, out hit)) { Hex hex = hit.collider.GetComponent <Hex>(); if (hex != null) { isPopulated++; direction = i + 3; if (direction > 5) { direction -= 6; } if (hex.CheckValidity(direction, fieldType[i])) { isValid++; } } } } return((isPopulated != 0) && (isPopulated == isValid)); }
// Update is called once per frame void Update() { if (pointer != null) { Vector3 position = Camera.main.ScreenToWorldPoint(Input.mousePosition); position = HexMath.HexToPixel(HexMath.PixelToHex(position)); pointer.transform.position = position; if (Input.GetMouseButtonDown(0) && pointer.CheckNeighbors()) { pointer.EndDrag(); pointer = null; pointer = InstantiateHex(); pointer.BeginDrag(); } } }