Skip to content

Commit 9a6f336

Browse files
committed
commit inicial
1 parent 2c7447f commit 9a6f336

10 files changed

Lines changed: 128 additions & 0 deletions

File tree

Assets/AudioManager.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/AudioManager/Example.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
13.4 KB
Binary file not shown.

Assets/AudioManager/Example/Example.unity.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/AudioManager/Prefab.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
8.16 KB
Binary file not shown.

Assets/AudioManager/Prefab/AudioManager.prefab.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/AudioManager/Script.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using UnityEngine;
2+
using UnityEngine.Audio;
3+
4+
public class AudioManager : MonoBehaviour {
5+
6+
public AudioSource musicSource, effectSource;
7+
public float lowPitchRange = .95f;
8+
public float highPitchRange = 1.05f;
9+
10+
[HideInInspector]
11+
public bool musicOn, effectOn;
12+
13+
public static AudioManager instance = null;
14+
15+
void Awake () {
16+
if (instance == null) {
17+
instance = this;
18+
}
19+
else if (instance != this) {
20+
Destroy(gameObject);
21+
}
22+
DontDestroyOnLoad(gameObject);
23+
}
24+
25+
private void Start() {
26+
musicOn = true;
27+
effectOn = true;
28+
}
29+
30+
public void PlayEffect(AudioClip clip, float duracao = 1f, float volume = 1f, float pitch = 1f) {
31+
if (!effectOn) return;
32+
effectSource.volume = volume;
33+
effectSource.pitch = pitch;
34+
effectSource.PlayOneShot(clip, duracao);
35+
36+
}
37+
38+
public void PlayRandomEffect(AudioClip[] clips, float duracao = 1f, float volume = 1f) {
39+
int random = UnityEngine.Random.Range(0, clips.Length);
40+
float randomPitch = UnityEngine.Random.Range(lowPitchRange, highPitchRange);
41+
42+
PlayEffect(clips[random], duracao, volume, randomPitch);
43+
}
44+
45+
public void PlayMusic(AudioClip clip) {
46+
if (!musicOn) return;
47+
musicSource.clip = clip;
48+
musicSource.Play();
49+
}
50+
51+
public void switchMusic() {
52+
if (musicOn) {
53+
musicSource.Stop();
54+
} else {
55+
musicSource.Play();
56+
}
57+
musicOn = !musicOn;
58+
}
59+
60+
public void switchEffect() {
61+
effectOn = !effectOn;
62+
}
63+
}

Assets/AudioManager/Script/AudioManager.cs.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)