// Update is called once per frame
    void Update()
    {
        if (unit != null)
        {
            if (unit.canOpenDoor())
            {
                transform.FindChild("CharacterPanel").FindChild("DoorButton").GetComponent <Button>().interactable = true;
            }
            else
            {
                transform.FindChild("CharacterPanel").FindChild("DoorButton").GetComponent <Button>().interactable = false;
            }


            if (unit.getCurrentWeapon().type != lastWeaponType)
            {
                Transform attackButton = transform.Find("CharacterPanel").FindChild("AttackButton");

                attackButton.FindChild("CrossHair").gameObject.SetActive(false);
                attackButton.FindChild("Sword").gameObject.SetActive(false);
                attackButton.FindChild("Shield").gameObject.SetActive(false);

                if (unit.getCurrentWeapon().type == WeaponType.ranged)
                {
                    attackButton.FindChild("CrossHair").gameObject.SetActive(true);
                }

                else if (unit.getCurrentWeapon().type == WeaponType.melee)
                {
                    attackButton.FindChild("Sword").gameObject.SetActive(true);
                }

                else if (unit.getCurrentWeapon().type == WeaponType.shield)
                {
                    attackButton.FindChild("Shield").gameObject.SetActive(true);
                }


                lastWeaponType = unit.getCurrentWeapon().type;
            }
            if (unit.hasAttacked() || unit.isMoving() || (unit.getCurrentWeapon().type == WeaponType.shield && ((Shield)unit.getCurrentWeapon()).isBroken(unit.GetInstanceID())))
            {
                Transform attackButton = transform.Find("CharacterPanel").FindChild("AttackButton");
                attackButton.GetComponent <Button>().interactable = false;
            }
            else
            {
                Transform attackButton = transform.Find("CharacterPanel").FindChild("AttackButton");
                attackButton.GetComponent <Button>().interactable = true;
            }
        }
    }
    void unitSelectedRightClick(RaycastHit hit, unitScript unit)
    {
        clickableTile tile = hit.collider.gameObject.GetComponent <clickableTile>();

        if (tile)
        {
            GridItem tilePos = tile.GetComponent <GridItem>();
            GridItem pos     = selected.GetComponent <GridItem>();

            if (!unit.hasMoved())
            {
                //draw path only if not in attack mode
                Vector2[] path = pathFinder.drawPath(tilePos.getPos(), !attackMode);


                if (path != null)
                {
                    if (!attackMode && !unit.hasMoved())
                    {
                        map.UnHilightMap();
                        //map.toggleHighlight(false, Color.white, pos.getX(), pos.getY(), unit.getSpeed());
                        unit.setPath(path);
                        pathFinder.setPathfinding(false);
                    }
                }
            }
            if (attackMode && unit.getCurrentWeapon().type == WeaponType.shield)
            {
                activateShield(unit, tilePos);
            }
        }
        //If not tile may be unit
        unitScript clickedUnit = hit.collider.gameObject.GetComponent <unitScript>();

        // if is enemy unit
        if (attackMode && !unit.hasAttacked() && clickedUnit && clickedUnit.getOwner() != 0)
        {
            Attack(unit, clickedUnit);
        }
    }
    void AttackCommand()
    {
        if (attackMode)
        {
            attackMode            = false;
            rangeRenderer.enabled = false;
            map.UnHilightMap();
            selectUnit(selected.GetComponent <unitScript>());
        }
        else
        {
            unitScript unit = selected.GetComponent <unitScript>();
            if (unit.hasAttacked())
            {
                return;
            }
            Weapon   currentWeapon = unit.getCurrentWeapon();
            GridItem pos           = selected.GetComponent <GridItem>();

            map.UnHilightMap();

            if (currentWeapon.type == WeaponType.melee)
            {
                MeleeWeapon currentMeleeWeapon = (MeleeWeapon)currentWeapon;
                map.toggleHighlight(true, Color.red, pos.getX(), pos.getY(), currentMeleeWeapon.range);
            }
            else if (currentWeapon.type == WeaponType.shield)
            {
                Shield currentShield = (Shield)currentWeapon;
                map.toggleHighlight(true, Color.yellow, pos.getX(), pos.getY(), currentShield.range);
            }

            attackMode = true;
            pathFinder.setPathfinding(false);
        }
    }