private void UpdateRain() { if (Game.GameTime.IsOnPause) { RainFallParticleSystem.Pause(true); RainExplosionParticleSystem.Pause(true); RainMistParticleSystem.Pause(true); volume = Mathf.Lerp(volume, 0.0f, Time.deltaTime * VolumeChangeSpeed); audioSourceRainCurrent.AudioSource.volume = volume; audioSourceRainLight.AudioSource.volume = volume; audioSourceRainMedium.AudioSource.volume = volume; audioSourceRainHeavy.AudioSource.volume = volume; } else { RainFallParticleSystem.Play(true); RainExplosionParticleSystem.Play(true); RainMistParticleSystem.Play(true); volume = Mathf.Lerp(volume, 0.5f, Time.deltaTime * VolumeChangeSpeed); audioSourceRainCurrent.AudioSource.volume = volume; audioSourceRainLight.AudioSource.volume = volume; audioSourceRainMedium.AudioSource.volume = volume; audioSourceRainHeavy.AudioSource.volume = volume; } // keep rain and mist above the player if (RainFallParticleSystem != null) { if (FollowCamera) { var s = RainFallParticleSystem.shape; s.shapeType = ParticleSystemShapeType.ConeVolume; RainFallParticleSystem.transform.position = Camera.transform.position; RainFallParticleSystem.transform.Translate(0.0f, RainHeight, RainForwardOffset); RainFallParticleSystem.transform.rotation = Quaternion.Euler(0.0f, Camera.transform.rotation.eulerAngles.y, 0.0f); if (RainMistParticleSystem != null) { var s2 = RainMistParticleSystem.shape; s2.shapeType = ParticleSystemShapeType.HemisphereShell; Vector3 pos = Camera.transform.position; pos.y += RainMistHeight; RainMistParticleSystem.transform.position = pos; } } else { var s = RainFallParticleSystem.shape; s.shapeType = ParticleSystemShapeType.Box; if (RainMistParticleSystem != null) { var s2 = RainMistParticleSystem.shape; s2.shapeType = ParticleSystemShapeType.Box; Vector3 pos = RainFallParticleSystem.transform.position; pos.y += RainMistHeight; pos.y -= RainHeight; RainMistParticleSystem.transform.position = pos; } } } }
private void EmitExplosion(ref Vector3 pos) { int count = UnityEngine.Random.Range(2, 5); while (count != 0) { float xVelocity = UnityEngine.Random.Range(-2.0f, 2.0f) * cameraMultiplier; float yVelocity = UnityEngine.Random.Range(1.0f, 3.0f) * cameraMultiplier; float lifetime = UnityEngine.Random.Range(0.1f, 0.2f); float size = UnityEngine.Random.Range(0.05f, 0.1f) * cameraMultiplier; RainExplosionParticleSystem.Emit(pos, new Vector3(xVelocity, yVelocity, 0.0f), size, lifetime, explosionColor); count--; } }
private void EmitExplosion(ref Vector3 pos) { int count = UnityEngine.Random.Range(2, 5); while (count != 0) { float xVelocity = UnityEngine.Random.Range(-2.0f, 2.0f) * cameraMultiplier; float yVelocity = UnityEngine.Random.Range(1.0f, 3.0f) * cameraMultiplier; float lifetime = UnityEngine.Random.Range(0.1f, 0.2f); float size = UnityEngine.Random.Range(0.05f, 0.1f) * cameraMultiplier; ParticleSystem.EmitParams param = new ParticleSystem.EmitParams(); param.position = pos; param.velocity = new Vector3(xVelocity, yVelocity, 0.0f); param.startLifetime = lifetime; param.startSize = size; param.startColor = explosionColor; RainExplosionParticleSystem.Emit(param, 1); count--; } }