private void Update() { if (Input.GetKeyDown(KeyCode.O) && Id == 0 || Input.GetKeyDown(KeyCode.P) && Id == 1) { Die(); } float vertical = ReInput.players.GetPlayer(Id).GetAxisRaw("Vertical"); _bubblesAnimator.GetComponent <SpriteRenderer>().enabled = (Mathf.Abs(vertical) > 0.5f); ParticleSystem system = _bubblesAnimator.GetComponentInChildren <ParticleSystem>(); if (system != null) { if ((Mathf.Abs(vertical) > 0.5f) && !system.isEmitting) { system.Play(); } else if (Mathf.Abs(vertical) < 0.5f && system.isEmitting) { system.Stop(); } } if (Mathf.Abs(vertical) > 0.5f) { if (!_playingSound) { _playingSound = true; _audioRemote = AudioManager.PlaySound("Accelerate"); } } else { if (_playingSound) { _audioRemote.FadeOut(); _playingSound = false; } } if (!Invincible) { return; } _currentInvincibilityTime += Time.deltaTime; if (_currentInvincibilityTime > _invincibilityDuration) { //Stop animation AnimationController.SetBool("Damaged", false); Invincible = false; } }
private IEnumerator FadeOutRoutine(AudioRemote remote) { float t = remote.FadeOutTime; float startVolume = remote._source.volume; while (t >= 0.0f) { remote._source.volume = startVolume * (t / remote.FadeOutTime); t -= Time.deltaTime; yield return(null); } remote._source.Stop(); }
IEnumerator DelayOnSpawn() { yield return(new WaitForSeconds(DelayBeforeSpawn)); foreach (PlayAnimation animator in Animators) { animator.PlayAnim(); } AudioRemote remote = AudioManager.PlaySound("Bubbles"); yield return(new WaitForSeconds(DelayBeforeBubbles)); remote.FadeOut(); foreach (PlayAnimation animator in Animators) { animator.StopAnim(); } SpawnBubbles(); }
public static void FadeOutSound(AudioRemote remote) { _instance.StartCoroutine(_instance.FadeOutRoutine(remote)); }