Beispiel #1
0
        public void GetDamage(int damage)
        {
            if (m_Health > 0)
            {
                m_Health -= damage;
                if (m_Health <= 0)
                {
                    m_Health = 0;
                }

                float healthRatio = m_Health / (float)m_MaxHealth;
                OnGetDamage?.Invoke(healthRatio);

                if (m_Health == 0)
                {
                    m_Explosion.transform.SetParent(null, true);
                    m_Explosion.gameObject.SetActive(true);
                    m_Explosion.Play(true);
                    gameObject.SetActive(false);
                    AudioSource.PlayClipAtPoint(m_ExplosionSound.m_Audio, transform.position, m_ExplosionSound.m_Volume);
                }
                else
                {
                    m_DamageSoundPlayer.PlayOneShot(m_DamageSound.m_Audio, m_DamageSound.m_Volume);
                }
            }
        }
Beispiel #2
0
        private void Fire()
        {
            Quaternion rotation = Quaternion.LookRotation(m_TurretDirection.forward, Vector3.up);
            Bullet     bullet   = Instantiate(m_BulletPrefab, m_ShootPosition.position, rotation);

            bullet.Shoot(m_TurretDirection.forward);

            AutoDestroyParticle particle = Instantiate(m_FireParticlePrefab, m_ShootPosition.position, Quaternion.identity);

            particle.Play(true);
            m_SoundPlayer.PlayOneShot(m_ShootSound.m_Audio, m_ShootSound.m_Volume);
        }
Beispiel #3
0
 private void PlayExplosion(AutoDestroyParticle particle)
 {
     particle.transform.SetParent(null, true);
     particle.gameObject.SetActive(true);
     particle.Play(true);
 }