public void SetDragging()
 {
     if (draggingTile == null)
     {
         draggingTile = this;
         hovered      = this;
     }
 }
        public bool SetTile(Hex hex, HexaGridTile tile)
        {
            int n = N;

            grid [hex.q + n, hex.r + n + Mathf.Min(0, hex.q)] = tile;
            if (tile != null)
            {
                tile.transform.localPosition = GetPosition(hex);
                if (lockOnPlace)
                {
                    tile.Lock();
                }
                tile.gameObject.layer = gameObject.layer;
            }
            return(true);
        }
        void Update()
        {
            if (Input.GetMouseButtonUp(0) && draggingTile == this)
            {
                draggingTile = null;
                Vector3 groundPos = playingField.GetMouseProjection(0);
                var     hex       = playingField.GetClosestHex(groundPos);
                if (playingField.GetDistanceToClosest(groundPos) < snapDistance * 1.4f && playingField.Fits(this, hex))
                {
                    if (playingField.SetTile(hex, this))
                    {
                        playingFieldPosition = hex;
                    }
                }
                else
                {
                    Destroy(gameObject);
                }
            }

            if (hovering && !locked && !rotating)
            {
                if (Input.GetMouseButtonDown(0) && draggingTile == null)
                {
                    draggingTile = this;
                }

                if (hovering)
                {
                    var roto = Input.GetAxis("Rotate");
                    if (roto > rotoThreshold)
                    {
                        StartCoroutine(animRotate(currentRotation + 1));
                    }
                    else if (roto < -rotoThreshold)
                    {
                        StartCoroutine(animRotate(currentRotation - 1));
                    }

                    if (Input.GetButtonDown("Submit") || Input.GetMouseButtonDown(2))
                    {
                        tile.Generate();
                    }
                }
            }
        }
        public bool Fits(HexaGridTile tile, Hex hex)
        {
            if (!IsFree(hex))
            {
                return(false);
            }
            if (everythingFits)
            {
                return(true);
            }
            foreach (Directions d in System.Enum.GetValues(typeof(Directions)))
            {
                var other = GetTile(hex.GetNeighbour(d));
                Debug.Log(other);
                if (other && other.HasBridge(d.Opposing()) != tile.HasBridge(d))
                {
                    return(false);
                }
            }

            return(true);
        }