0% found this document useful (0 votes)
8 views4 pages

Audio Manager

Uploaded by

pejrt251009
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views4 pages

Audio Manager

Uploaded by

pejrt251009
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

C:\Users\yuvra\arcade_game\Assets\scripts\level_manager.

cs 1
1 using System;
2 using System.Collections;
3 using System.Collections.Generic;
4 using TMPro;
5 using UnityEngine;
6 using UnityEngine.Audio;
7 using UnityEngine.Rendering;
8 using UnityEngine.Rendering.Universal;
9 using UnityEngine.SceneManagement;
10 using UnityEngine.SocialPlatforms.Impl;
11 using UnityEngine.UI;
12 public class level_manager : MonoBehaviour
13 {
14 [SerializeField] private Text player_stats_text, player_stats_text_2;
15 public bool isMainMenu;
16 public Animator animator_t;
17 [SerializeField] private Text exitText1, exitText2;
18 [SerializeField] private player_movment p_m;
19 private bool isDead = false;
20 [SerializeField] private Animator death_animator;
21 [SerializeField] private AudioSource audio_source;
22 [SerializeField] private AudioClip[] clips;
23 [SerializeField] private Light2D public_light;
24 public bool toAudio;
25 [SerializeField] private AudioSource clip_audio, bg_audio;
26 public audioManager audioManager;
27 public AudioMixer a_m;
28 [SerializeField] private GameObject Pause_menu;
29 private bool StopRenderShadows;
30
31 private void Awake()
32 {
33 audioManager = GetComponent<audioManager>();
34 }
35
36 public void Start()
37 {
38 // a_m.SetFloat("volume", PlayerPrefs.GetFloat("volume"));
39 // bg_audio.volume = PlayerPrefs.GetFloat("volume") / 20;
40 // bg_audio.Play();
41 if (isMainMenu && PlayerPrefs.HasKey("Firstime"))
42 {
43 PlayerPrefs.DeleteAll();
44 PlayerPrefs.SetInt("Firstime", 1);
45 }
46 if (isMainMenu && PlayerPrefs.GetInt("FirsTime") == 0)
47 {
48 PlayerPrefs.SetInt("FirsTime", 1);
49 PlayerPrefs.Save();
C:\Users\yuvra\arcade_game\Assets\scripts\level_manager.cs 2
50 SceneManager.LoadScene(7);
51 }
52 if (isMainMenu)
53 {
54 StartCoroutine(StartFadeIn(a_m,"volume" ,2, 10));
55 a_m.SetFloat("lowfreq", 22000);
56 player_stats_text.text = "Max Score - " + PlayerPrefs.GetFloat
("score");
57 player_stats_text_2.text = "Total Coins - " +
PlayerPrefs.GetInt("coins");
58 }
59 }
60
61 /*public static IEnumerator startFadeIn(AudioMixer aMixer,float
duration, bool fadeIn )
62 {
63 bool keepFadeIn = true;
64 bool keepFadeOut = false;
65 aMixer.SetFloat("volume", -80);
66 yield return null;
67 }*/
68
69 public static IEnumerator StartFadeIn(AudioMixer audioMixer, string
exposedParam, float duration, float targetVolume)
70 {
71 audioMixer.SetFloat("volume", -80);
72 float currentTime = 0;
73 float currentVol;
74 audioMixer.GetFloat(exposedParam, out currentVol);
75 currentVol = Mathf.Pow(10, currentVol / 20);
76 float targetValue = Mathf.Clamp(targetVolume, 0.00001f, 1f);
77 while (currentTime < duration)
78 {
79 currentTime += Time.time;
80 float newVol = Mathf.Lerp(currentVol, targetValue,
currentTime / duration);
81 audioMixer.SetFloat(exposedParam, Mathf.Log10(newVol) *20);
82 yield return null;
83 }
84 yield break;
85 }
86
87 public static IEnumerator StartFade(AudioMixer audioMixer, string
exposedParam, float duration, float targetVolume)
88 {
89 float currentTime = 0;
90 float currentVol;
91 audioMixer.GetFloat(exposedParam, out currentVol);
92 currentVol = Mathf.Pow(10, currentVol / 20);
C:\Users\yuvra\arcade_game\Assets\scripts\level_manager.cs 3
93 float targetValue = Mathf.Clamp(targetVolume, 0.0001f, 1);
94 while (currentTime < duration)
95 {
96 currentTime += Time.deltaTime;
97 float newVol = Mathf.Lerp(currentVol, targetValue,
currentTime / duration);
98 audioMixer.SetFloat(exposedParam, Mathf.Log10(newVol) * 20);
99 yield return null;
100 }
101 yield break;
102 }
103 public void Update()
104 {
105 if (isMainMenu == false)
106 {
107 if (p_m.health <= 0 && isDead == false)
108 {
109 isDead = true;
110 audioManager.died = true;
111 public_light.shadowsEnabled = false;
112 public_light.shadowVolumeIntensity = 0;
113 p_m.end_menu.SetActive(true);
114 player_movment this_data =
p_m.GetComponent<player_movment>();
115 save_load.save(this_data);
116 Instantiate(p_m.particles_5, transform.position,
Quaternion.identity, p_m.particleDump);
117 p_m.healthText.text = "error! health not found!";
118 p_m.end_score_text.text = "Total Score - " + p_m.score;
119 p_m.end_coin_text.text = "Total Coins Collected - " +
p_m.coins;
120 Destroy(p_m.gameObject);
121 }
122 if (p_m.health <= 0)
123 {
124 if (!p_m.death_animator.GetCurrentAnimatorStateInfo
(0).IsName("start_death_menu"))
125 {
126 death_animator.SetBool("startMenu", true);
127 }
128 }
129
130 if (StopRenderShadows == true && isDead == false)
131 {
132 public_light.shadowsEnabled = false;
133 public_light.shadowVolumeIntensity = 0;
134 }
135
136 /*if (StopRenderShadows == false && isDead == false)
C:\Users\yuvra\arcade_game\Assets\scripts\level_manager.cs 4
137 {
138 public_light.shadowsEnabled = true;
139 public_light.shadowVolumeIntensity = 0.526f;
140 }*/
141 }
142 }
143 public void quit()
144 {
145 StopRenderShadows = true;
146 StartCoroutine(loadasyncLevel("Main_Menu"));
147 Time.timeScale = 1;
148 }
149 public void restart()
150 {
151 StopRenderShadows = true;
152 StartCoroutine(loadasyncLevel(SceneManager.GetActiveScene
().name));
153 Time.timeScale = 1;
154 }
155 public void loadScene(string sceneName)
156 {
157 clip_audio.Play();
158 StartCoroutine(StartFade(a_m, "volume", 1, 0));
159 StartCoroutine(loadasyncLevel(sceneName));
160 }
161 public IEnumerator loadasyncLevel(string scene_name)
162 {
163 if (isMainMenu == false)
164 {
165 exitText1.text = "";
166 exitText2.text = "";
167 }
168 animator_t.SetTrigger("start");
169 yield return new WaitForSecondsRealtime(1.01f);
170 SceneManager.LoadScene(scene_name);
171 }
172 public void quitApplication()
173 {
174 animator_t.SetTrigger("start");
175 clip_audio.Play();
176 StartCoroutine(wquitApplication());
177 }
178 IEnumerator wquitApplication()
179 {
180 yield return new WaitForSeconds(1);
181 Application.Quit();
182 }
183 }
184

You might also like