Пример #1
0
    protected bool activateShield(unitScript unit, GridItem position)
    {
        if (!(unit.getCurrentWeapon().type == WeaponType.shield))
        {
            return(false);
        }
        Shield currentShield = (Shield)unit.getCurrentWeapon();

        if (currentShield.isBroken(unit.GetInstanceID()))
        {
            return(false);
        }

        if (currentShield.getShield(unit.GetInstanceID()) != null)
        {
            Destroy(currentShield.getShield(unit.GetInstanceID()));
        }

        //Check position is within range
        if (currentShield == null || Vector2.Distance(unit.GetComponent <GridItem>().getPos(), position.getPos()) > currentShield.range)
        {
            return(false);
        }
        //Create the game object
        //TODO- Fix the roation and shape of shields to be frontal not surround
        Vector3 toPosition = position.getVectorPostion() - unit.GetComponent <GridItem>().getVectorPostion();
        float   rotation   = Vector3.Angle(new Vector3(0, 0, 1), Vector3.Cross(toPosition, new Vector3(0, 1, 0)));

        print(rotation);
        GameObject newShield = Instantiate <GameObject>(Resources.Load <GameObject>("Units/Shield"), position.getVectorPostion(), Quaternion.Euler(0, rotation, 0));

        currentShield.setShield(unit.GetInstanceID(), newShield);

        newShield.GetComponent <shieldScript>().setStats(controllerID, unit.getSmarts() * 3);
        //Check it's collisions with other shields
        currentShield.shieldBreakCheck();


        unit.activateAttack();

        print("ACTIVATE SHIELD");
        map.UnHilightMap();



        return(true);
    }
    public void loadCharacter(unitScript u, bool ally = true)
    {
        if (ally)
        {
            unit = u;
        }
        Transform characterPanel = transform;
        Transform statPannel     = characterPanel.Find(ally?"StatPanel":"EnemyStatPanel");

        UnityEngine.UI.Text nameText = statPannel.Find("Name").GetComponent <UnityEngine.UI.Text>();
        nameText.text = u.getName();

        statPannel.FindChild("Image").GetComponent <Image>().sprite = u.getPortrait();

        var strengthText = statPannel.Find("Strength").GetComponent <UnityEngine.UI.Text>();

        strengthText.text = u.getStrength().ToString();

        var skillText = statPannel.Find("Skill").GetComponent <UnityEngine.UI.Text>();

        skillText.text = u.getSkill().ToString();

        var speedText = statPannel.Find("Speed").GetComponent <UnityEngine.UI.Text>();

        speedText.text = u.getSpeed().ToString();

        var smartsText = statPannel.Find("Smarts").GetComponent <UnityEngine.UI.Text>();

        smartsText.text = u.getSmarts().ToString();

        loadHealth(u.getHealth(), u.getMaxHealth(), statPannel);

        if (ally)
        {
            if (unit.doorsWithinRange.Count > 0)
            {
                transform.FindChild("CharacterPanel").FindChild("DoorButton").GetComponent <Button>().interactable = true;
            }
            else
            {
                transform.FindChild("CharacterPanel").FindChild("DoorButton").GetComponent <Button>().interactable = false;
            }
        }

        loadWeaponData(u, ally);
    }