Esempio n. 1
0
        protected virtual void OnDestroy()
        {
            DamageSource melee = _meleeAttack.GetComponentInChildren <DamageSource>();

            melee.OnHit -= OnMeleeHit;

            Destroy(_meleeAttack);

            DamageSource dash = _dashAttack.GetComponent <DamageSource>();

            dash.OnHit -= OnDashHit;
        }
Esempio n. 2
0
        protected virtual void Start()
        {
            Debug.Assert(Config != null);
            Debug.Assert(_collider != null);
            Debug.Assert(_rigidBody2D != null);

            // here, we trigger our properties that have setters with bodies
            SkinWidth = _skinWidth;

            _enemyMask    = Config.EnemyMask;
            _activeAttack = Config.DefaultAttack;

            MaxJumps = Config.MaxJumps;

            UpdateLayerCollision();

            CharacterYoke = new Yoke();

            Inventory.Initialise(this, Config.DefaultContents);

            _characterSprite.color = Config.SpriteTint;

            //Setup melee attack
            _meleeAttackEndTime   = Time.time;
            _lastRangedAttackTime = Time.time;

            Debug.Assert(Config.MeleeAttackPrefab != null);
            _meleeAttack = Instantiate(Config.MeleeAttackPrefab, transform);
            Debug.Assert(_meleeAttack != null);
            _meleeAttack.SetActive(false);
            DamageSource meleeDamageSource = _meleeAttack.GetComponentInChildren <DamageSource>();

            meleeDamageSource.Setup(this, Config.BaseMeleeDamage);
            meleeDamageSource.OnHit += OnMeleeHit;

            //Setup ranged attack
            _rangedAttackPool = new PrefabPool(Config.RangedAttackPrefab, 5, false, transform);

            //Setup dash attack
            _dashAttackHighlightSprite       = _dashAttack.GetComponent <SpriteRenderer>();
            _dashAttackHighlightSprite.color = Config.SpriteTint;

            _dashAttackCollider         = _dashAttack.GetComponent <Collider2D>();
            _dashAttackCollider.enabled = false;

            DamageSource dashDamageSource = _dashAttack.GetComponent <DamageSource>();

            dashDamageSource.Setup(this, Config.DashAttackBaseDamage);
            dashDamageSource.OnHit += OnDashHit;

            _dashAttack.SetActive(false);
        }
Esempio n. 3
0
 public void Damage(DamageSource damage)
 {
     ModifyHealth(-(int)damage.Damage);
     OnDamaged.InvokeSafe(damage);
 }