// Deactivate the gameObject for reuse later... // virtual public void DeInitBullet() { // If we've ever been alive (fired) then we can add camera shake if (m_bIsAlive) { AddCameraShake gc = GetComponent <AddCameraShake>(); if (null != gc) { gc.AddShakeToCamera(); } } // Set defaults m_bIsAlive = false; m_vTrajectory = Vector2.zero; m_fMovementSpeed = 0.0f; // Send physics to sleep and cleanup... { if (null != m_gcRgdBdy) { m_gcRgdBdy.velocity = Vector2.zero; m_gcRgdBdy.Sleep(); gameObject.SetActive(false); } if (null != m_gcCollider) { m_gcCollider.enabled = false; } } }
// Because we can call to kill an object immediately, we've split it out from the collision function // public virtual void DoOnImpactFromPlayer(uint iDamage, bool bIsPlayerOption = false, bool bPlayerPhysicalCollision = false) { if (bIsPlayerOption && m_bIgnorePlayerOptionKills) { return; } GameInstance gi = GameInstance.Object; GAssert.Assert(null != gi, "Unable to get Game Instance!"); m_iHitPointsRemaining = (int)MathUtil.Clamp(m_iHitPointsRemaining - (int)iDamage, 0, Types.s_iPLAYER_MaxDamage); if (m_iHitPointsRemaining <= 0) { PlayDeathEffects();; // Add optionals AddScore gcScore = GetComponent <AddScore>(); if (null != gcScore) { gcScore.AddScoreToPlayer(); } UnlockAchievement gcAchievement = GetComponent <UnlockAchievement>(); if (null != gcAchievement) { gcAchievement.AddAchievement(); } AddCameraShake gcShake = GetComponent <AddCameraShake>(); if (null != gcShake) { gcShake.AddShakeToCamera(); } // BUT, we only spawn prefabs if we've been shot, not if it's a physical collision if (!bPlayerPhysicalCollision) { SpawnPrefab[] aPrefabSpawns = GetComponents <SpawnPrefab>(); if (aPrefabSpawns.Length > 0) { for (int i = 0; i < aPrefabSpawns.Length; ++i) { aPrefabSpawns[i].DoSpawnPrefab(); } } } // Die Die Die! Destroy(gameObject); return; } // Didn't die? Play the impact ting audio... if (m_bPlaySFXOnHit) { gi.GetAudioManager().PlayAudioAtLocation(transform.position, m_iSFX_Impact); } }
public override void DeInitBullet() { // If we've ever been alive (fired) then we can add camera shake if (m_bIsAlive) { AddCameraShake gc = GetComponent <AddCameraShake>(); if (null != gc) { gc.AddShakeToCamera(); } } Destroy(gameObject); }
// Because we can call to kill an object immediately, we've split it out from the collision function // public override void DoOnImpactFromPlayer(uint iDamage, bool bIsPlayerOption = false, bool bPlayerPhysicalCollision = false) { if (m_bUpdateLoop || bIsPlayerOption) { return; } GameInstance gi = GameInstance.Object; GAssert.Assert(null != gi, "Unable to get Game Instance!"); m_iHitPointsRemaining = (int)MathUtil.Clamp(m_iHitPointsRemaining - (int)iDamage, 0, Types.s_iPLAYER_MaxDamage); if (m_iHitPointsRemaining <= 0) { // Turn off the sprite and collider (Bespoke to the heart) GetComponent <SpriteRenderer>().enabled = false; GetComponent <PolygonCollider2D>().enabled = false; // Move particles closer to camera, so they appear over everything Vector3 vPos = transform.position; vPos.z = Types.s_fPOS_FrontLayerZ; // Spawn the effects if (m_bPixelShatter) { SpriteToParticleSystem.ExplodeSprite(transform.position, Types.s_fVEL_PixelShatterVelocity, m_goPixelShatterPrefab, m_gcSprite, m_iPixelShatterTTL); } if (m_bPlaySFXOnDeath) { GameInstance.Object.GetAudioManager().PlayAudioAtLocation(transform.position, m_iSFX_Explosion); } if (m_bSpawnExplosionEffect && null != m_goExplosionPrefab) { Instantiate(m_goExplosionPrefab, transform.position, Quaternion.identity); } // Add optionals AddScore gcScore = GetComponent <AddScore>(); if (null != gcScore) { gcScore.AddScoreToPlayer(); } AddCameraShake gcShake = GetComponent <AddCameraShake>(); if (null != gcShake) { gcShake.AddShakeToCamera(); } SpawnPrefab[] aPrefabSpawns = GetComponents <SpawnPrefab>(); if (aPrefabSpawns.Length > 0) { for (int i = 0; i < aPrefabSpawns.Length; ++i) { aPrefabSpawns[i].DoSpawnPrefab(); } } m_bUpdateLoop = true; GameMode.BeginCompletionSequence(); } // Didn't die? Play the impact ting audio... if (m_bPlaySFXOnHit) { gi.GetAudioManager().PlayAudioAtLocation(transform.position, m_iSFX_Impact); } }