Example #1
0
    public void RemovePlayerRodent(Rodent r)
    {
        if (_PlayerRodents != null)
        {
            if (_PlayerRodents.Contains(r))
            {
                _PlayerRodents.Remove(r);
            }
            _rm.UpdateCurrentPopulation();

            //Keep organized in hierarchy
            if (!r.isDead())
            {
                r.gameObject.transform.SetParent(_NeutralRodentDummy);
            }

            //Debug.Log("Set to neutralStack:" + r.gameObject);
        }
    }
Example #2
0
    // Handles the rat attacking an enemy
    IEnumerator Attack()
    {
        // Play animation
        //Debug.Log("Attack!Rat@" + Time.time);

        if (canAttack)
        {
            canAttack = false;
            if (anims)
            {
                // Put attack animation here
                anims.SetTrigger(ATK_ANIMATION_TRIGGER);
            }
            // For rodents
            Rodent      _EnemyRodent = currentTarget.GetComponent <Rodent>();
            PlayerStats king         = currentTarget.GetComponent <PlayerStats>();

            if (_EnemyRodent)
            {
                if (!_EnemyRodent.isDead())
                {// Reduce enemy health
                    _EnemyRodent.Damage(attackDamage);
                    SoundManager.Instance.PlayCombat();
                }
                else
                {
                    _inRange.Remove(currentTarget);
                    // print("Called from Dead Rodent found");
                    FindNextTargetInRange();
                }
            }
            else if (king)
            {
                if (!king.isDead())
                {
                    king.Damage(attackDamage);
                    SoundManager.Instance.PlayCombat();
                }
                else
                {
                    _inRange.Remove(currentTarget);
                    FindNextTargetInRange();
                }
            }
            else
            {
                BuildableObject _enemyBuilding = currentTarget.GetComponent <BuildableObject>();
                if (_enemyBuilding.getHP() > 0 && _enemyBuilding.getType() != BuildableObject.BuildingType.TownCenter)
                {
                    _enemyBuilding.Damage(attackDamage);
                    SoundManager.Instance.PlayCombat();
                }
                else
                {
                    _inRange.Remove(currentTarget);
                    // print("Called from Dead Building found");
                    FindNextTargetInRange();
                }
            }


            yield return(new WaitForSeconds(1.16f)); //Length of attack animation

            canAttack = true;
        }
    }