Exemple #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);
    }
    // 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;
            }
        }
    }