mirror of
https://github.com/DerTyp7/defrain-shooter-unity.git
synced 2025-10-29 12:52:07 +01:00
created audio manager and Sound class
This commit is contained in:
8
Assets/Scripts/Audio.meta
Normal file
8
Assets/Scripts/Audio.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b6dcdcc23d4d29b468275ced8b179728
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
51
Assets/Scripts/Audio/AudioManager.cs
Normal file
51
Assets/Scripts/Audio/AudioManager.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using UnityEditor.Audio;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public class AudioManager : MonoBehaviour
|
||||
{
|
||||
public Sound[] sounds;
|
||||
|
||||
public static AudioManager instance;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if(instance == null)
|
||||
instance = this;
|
||||
else
|
||||
{
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
|
||||
DontDestroyOnLoad(gameObject);
|
||||
|
||||
foreach(Sound s in sounds)
|
||||
{
|
||||
s.source = gameObject.AddComponent<AudioSource>();
|
||||
s.source.clip = s.clip;
|
||||
|
||||
s.source.volume = s.volume;
|
||||
s.source.pitch = s.pitch;
|
||||
s.source.loop = s.loop;
|
||||
}
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
// Enter Music here
|
||||
}
|
||||
|
||||
|
||||
public void Play(string name)
|
||||
{
|
||||
Sound s = Array.Find(sounds, sound => sound.name == name);
|
||||
if(s == null)
|
||||
{
|
||||
Debug.LogWarning("Sound: " + s.name + " not found!");
|
||||
return;
|
||||
}
|
||||
|
||||
s.source.Play();
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Audio/AudioManager.cs.meta
Normal file
11
Assets/Scripts/Audio/AudioManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0018a9494d9c3f5439fea5ecf8a53a26
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
21
Assets/Scripts/Audio/Sound.cs
Normal file
21
Assets/Scripts/Audio/Sound.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using UnityEngine.Audio;
|
||||
using UnityEngine;
|
||||
|
||||
[System.Serializable]
|
||||
public class Sound
|
||||
{
|
||||
public string name;
|
||||
|
||||
public AudioClip clip;
|
||||
|
||||
[Range(0f, 1f)]
|
||||
public float volume;
|
||||
|
||||
[Range (.1f, 3f)]
|
||||
public float pitch;
|
||||
|
||||
[HideInInspector]
|
||||
public AudioSource source;
|
||||
|
||||
public bool loop;
|
||||
}
|
||||
11
Assets/Scripts/Audio/Sound.cs.meta
Normal file
11
Assets/Scripts/Audio/Sound.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 19dd45dc7a1b8284aabf85e506a4c065
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -67,6 +67,7 @@ public class HomeSceneBtnScript : MonoBehaviour, IPointerEnterHandler, IPointerE
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
isHovering = true;
|
||||
FindObjectOfType<AudioManager>().Play("test");
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
|
||||
Reference in New Issue
Block a user