public void OnTriggerEnter2D(Collider2D col) { // Destroy Enemy bullets if (col.gameObject.CompareTag(Types.s_sTag_EnemyBullets)) { Destroy(col.gameObject); } // Pass max damage to anything else... TrackHitPoints gc = col.gameObject.GetComponent <TrackHitPoints>(); if (null != gc) { gc.DoOnImpactFromPlayer(Types.s_iPLAYER_MaxDamage, true); return; } }
// Pay audio / effects, and return to the pool // virtual public void OnCollisionEnter2D(Collision2D collision) { if (m_bIsAlive) { // Now do some checks to see what we hit. { // Env always killed the bullet, no matter where it comes from if (collision.gameObject.CompareTag(Types.s_sTAG_Environment) || collision.gameObject.CompareTag(Types.s_sTAG_Doorway)) { m_iDamageRemaining = 0; } // Enemy Bullets always subtract from Damage Remaining else if (collision.gameObject.CompareTag(Types.s_sTag_EnemyBullets)) { m_iDamageRemaining = (int)MathUtil.Clamp(m_iDamageRemaining - 1, 0, Types.s_iPLAYER_MaxDamage); } // Enemies and destructible items should subtract their hitpoints else if (collision.gameObject.CompareTag(Types.s_sTag_Enemy) || collision.gameObject.CompareTag(Types.s_sTag_Destructible)) { // But... if we're a player bullet we also need to tell the Enemy how much damage we're doing! // Enemy bullets should just die on impact... if (!gameObject.CompareTag(Types.s_sTag_PlayerBullets)) { m_iDamageRemaining = 0; } else { TrackHitPoints gc = collision.gameObject.GetComponent <TrackHitPoints>(); if (null != gc) { int iHitPoints = gc.GetHitPointsRemaining(); int iDamageAfter = (int)MathUtil.Clamp(m_iDamageRemaining - iHitPoints, 0, Types.s_iPLAYER_MaxDamage); gc.DoOnImpactFromPlayer((uint)m_iDamageRemaining); m_iDamageRemaining = iDamageAfter; } // If an enemy doesn't have TrackHitPoints it's invulnerable, so kill this bullet else { m_iDamageRemaining = 0; } } } // Anything remaining is untagged, so kill the bullet just in case... else { m_iDamageRemaining = 0; } } // Die if we need to... if (m_iDamageRemaining == 0) { Vector3 vPos = new Vector3(collision.contacts[0].point.x, collision.contacts[0].point.y, Types.s_fPOS_FrontLayerZ); vPos += new Vector3(collision.contacts[0].normal.x, collision.contacts[0].normal.y, 0.0f) * Types.s_fPOS_ImpactEffectSpawnOffset; if (null != m_goImpactParticleEffect) { Instantiate(m_goImpactParticleEffect, vPos, Quaternion.identity); } GameInstance.Object.GetAudioManager().PlayAudioAtLocation(transform.position, m_iDespawnEffect); DeInitBullet(); } } }