Exemplo n.º 1
0
    private void Shoot()
    {
        if (Input.GetButtonDown(m_Controls.shoot) && m_LastShootTime + m_SpaceshipParameters.shootCooldown < Time.time)
        {
            m_LastShootTime = Time.time; // Start cooldown
            Bullet bullet = Instantiate(m_Bullet, transform.position + (transform.forward * m_SpaceshipParameters.shootOffset), Quaternion.identity);

            // SFX
            bullet.AccessToAudioSource().clip = m_SpaceshipEffects.bulletSounds[m_BulletSoundIndex];
            bullet.AccessToAudioSource().Play();
            if (m_BulletSoundIndex < m_SpaceshipEffects.bulletSounds.Length - 1)
            {
                m_BulletSoundIndex++;
            }
            else
            {
                m_BulletSoundIndex = 0;
            }

            // Bullet physics
            bullet.SetAcceleration(transform.forward * bullet.EntityParameters.accelerationScalar);
            bullet.ApplyForces(false);
        }
    }