// TODO: QUESTION: The gameobject this is attached to does not have a trigger, and this does not get called when it is hit, but its child object // does have a collider which is a trigger. Why does this work? private void OnTriggerEnter2D(Collider2D collision) { bool attacking = animator.GetBool(playerSMF.MeleeAttackHash); if (!attacking) { return; } // This checks the layers its hit. if (hittableLayers.value == (hittableLayers.value | (1 << collision.gameObject.layer))) { Damageable damageable = collision.GetComponentInParent <Damageable>(); if (damageable) { // The idea behind this is to call some function when hit (Lets say there was a desire for an explosion to dmg enemies on hit // From there that function could be called instead of invoke.) //OnDamageableHit.Invoke(this, damageable); if (damageable.health.CurHealth > 0) { damageable.TakeDamage(damage); if (damageable.health.CurHealth <= 0 && damageable.animator.GetBool(playerSMF.DeadHash) && (damageable.GetType().Equals(typeof(DamageableEnemy))) || damageable.GetType().IsSubclassOf(typeof(DamageableEnemy))) { damageablePlayer.GainHealth(((DamageableEnemy)damageable).enemy.pipValue); } } //if (disableDamageAfterHit) // DisableDamage(); } else { //OnNonDamageableHit.Invoke(this); } } }
// This Makes sense if we are problematically setting up scenes. //public Actor(Damageable dmg, Animator ani, SpriteRenderer sr, Rigidbody2D rb, BoxCollider2D bc, float baseMoveSpeed) //{ // damageable = dmg; // animator = ani; // spriteRenderer = sr; // rigidbody2D = rb; // boxCollider = bc; // baseMovementSpeed = baseMoveSpeed; //} public void setDamageable(Damageable dmg) { this.damageable = dmg; }