/// <summary> /// Do the actual fire. /// </summary> public void DoFire() { m_LastFireTime = Time.time; // Spawn a projectile which will move in the direction that the turret is facing var projectile = ObjectPool.Instantiate(m_Projectile, m_FirePoint.position, m_Transform.rotation).GetComponent <Projectile>(); projectile.Initialize(-m_Transform.forward, Vector3.zero, m_GameObject); var projectileCollider = projectile.GetComponent <Collider>(); // Ignore all of the turret's colliders to prevent the projectile from detonating as a result of the turret. if (projectileCollider != null) { for (int i = 0; i < m_Colliders.Length; ++i) { LayerManager.IgnoreCollision(projectileCollider, m_Colliders[i]); } } // Spawn a muzzle flash. if (m_MuzzleFlash) { ObjectPool.Instantiate(m_MuzzleFlash, m_MuzzleFlashLocation.position, m_MuzzleFlashLocation.rotation, m_Transform); } // Spawn any smoke. if (m_Smoke) { ObjectPool.Instantiate(m_Smoke, m_SmokeLocation.position, m_SmokeLocation.rotation); } // Play a firing sound. if (m_FireSound) { m_AudioSource.clip = m_FireSound; if (m_FireSoundDelay > 0) { m_AudioSource.PlayDelayed(m_FireSoundDelay); } else { m_AudioSource.Play(); } } }
/// <summary> /// Spawns a projectile which will move in the firing direction. /// </summary> protected virtual void ProjectileFire() { var rotation = Quaternion.LookRotation(FireDirection()); var projectileGameObject = ObjectPool.Spawn(m_Projectile, m_FirePoint.position, rotation * m_Projectile.transform.rotation); var projectile = Utility.GetComponentForType <Projectile>(projectileGameObject); projectile.Initialize(rotation * Vector3.forward, Vector3.zero, m_Character); var projectileCollider = Utility.GetComponentForType <Collider>(projectileGameObject); // Ignore all of the colliders to prevent the projectile from detonating as a result of the character. if (projectileCollider != null) { for (int i = 0; i < m_Colliders.Length; ++i) { LayerManager.IgnoreCollision(projectileCollider, m_Colliders[i]); } for (int i = 0; i < m_CharacterColliders.Length; ++i) { LayerManager.IgnoreCollision(projectileCollider, m_CharacterColliders[i]); } } }