Example #1
0
    // update determines the parameters of the gameobject's attack as they may be subject to change when swapping weaponry
    // this method also handles cooldowns on attacks; an attack cannot be made while the cooldown is above 0
    // finally, this method determines the direction in which an attack was made
    void Update()
    {
        _item  = gameObject.GetComponent <BattleItemScript>();
        rangeX = _item.item.rangeX;
        rangeZ = _item.item.rangeZ;
        // since an item's attack speed is the amount of times it can hit per second, the cooldown timer is the inverse
        _attackCooldownTime = 1.0 / _item.item.attackSpeed;

        attackCooldown  = attackCooldown <= 0 ? 0 : attackCooldown - Time.deltaTime;
        facingDirection = gameObject.CompareTag("Player") ? GetComponent <PlayerMovement>().facingDirection : GetComponent <Enemy>().facingDirection;
    }
Example #2
0
    void Attack()
    {
        BattleItemScript item = gameObject.GetComponent <BattleItemScript>();
        int rangeX = item.item.rangeX, rangeZ = item.item.rangeZ;

        GameObject attack = Instantiate(AttackHitBox, gameObject.transform.position + gameObject.transform.forward, Quaternion.identity); //spawns a boxcollider in the attack range

        attack.GetComponent <AttackCollider>().damage = item.item.damage;
        attack.GetComponent <BoxCollider2D>().size    = new Vector3(rangeX, 1, rangeZ);
        attack.tag = gameObject.tag == "Player" ? "PlayerAttack" : "EnemyAttack";
    }
Example #3
0
    void Start()
    {
        _item          = gameObject.GetComponent <BattleItemScript>();
        myRigidbody    = GetComponent <Rigidbody2D>();
        gameObject.tag = "Enemy";
        if (droppedItem == null)
        {
            GenerateDroppedItem();
        }                                                  // only generates a dropped item if one is not predetermined

        _wanderTimer = 0;
    }
    // when a battle item is selected in the inventory, it first checks if it is already the selected item. If it is, it deselects itself
    // and the default item is used. If not, it replaces the currently selected battle item
    public override void Use()
    {
        BattleItemScript script = PlayerMovement.instance.gameObject.GetComponent <BattleItemScript>();

        if (script.item == this)
        {
            script.removeItem();
            this.itemSprite = inactive;
        }
        else
        {
            script.setItem(this);
            this.itemSprite = active;
        }
    }