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 CheckForCollisionsRainParticles() { int count = 0; bool changes = false; if (CollisionMask != 0) { count = RainFallParticleSystem.GetParticles(particles); RaycastHit2D hit; for (int i = 0; i < count; i++) { Vector3 pos = particles[i].position + RainFallParticleSystem.transform.position; hit = Physics2D.Raycast(pos, particles[i].velocity.normalized, particles[i].velocity.magnitude * Time.deltaTime); if (hit.collider != null && ((hit.collider.gameObject.layer << 1) & CollisionMask) == (hit.collider.gameObject.layer << 1)) { if (hit.collider.gameObject.tag == "Player") { rainCount++; rainText.text = "Beckard hit " + rainCount + " times."; } if (CollisionLifeTimeRain == 0.0f) { particles[i].lifetime = 0.0f; } else { particles[i].lifetime = Mathf.Min(particles[i].lifetime, UnityEngine.Random.Range(CollisionLifeTimeRain * 0.5f, CollisionLifeTimeRain * 2.0f)); pos += (particles[i].velocity * Time.deltaTime); } changes = true; } } } if (RainExplosionParticleSystem != null) { if (count == 0) { count = RainFallParticleSystem.GetParticles(particles); } for (int i = 0; i < count; i++) { if (particles[i].lifetime < 0.24f) { Vector3 pos = particles[i].position + RainFallParticleSystem.transform.position; EmitExplosion(ref pos); } } } if (changes) { RainFallParticleSystem.SetParticles(particles, count); } }
protected override void Start() { RainFallParticleSystem.Play(); base.Start(); }