This commit is contained in:
GamerClassN7
2021-01-31 11:43:20 +01:00
parent e25dd8ddf4
commit 30e89e1a43
4 changed files with 163 additions and 16 deletions

View File

@@ -2,28 +2,27 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Audio;
using System;
public class Audiomanager : MonoBehaviour
{
public [] clips;
public AudioSound[] clips;
// Start is called before the first frame update
void Awake()
{
foreach (AudioClip c in clips)
foreach (AudioSound c in clips)
{
s.source = gameObject.AddComponent<AudionSource>();
s.source.clip = s.clip;
s.source.volume = s.volume;
s.source.pitch = s.pitch;
c.source = gameObject.AddComponent<AudionSource>();
c.source.clip = c.clip;
c.source.volume = c.volume;
c.source.pitch = c.pitch;
}
}
// Update is called once per frame
void Play(string name)
{
Sound s = Array.Find(clips, sound => sound.name == name);
s.source.Play()
AudioSound s = Array.Find(clips, sound => sound.name == name);
s.source.Play();
}
}

View File

@@ -0,0 +1,16 @@
using UnityEngine;
using UnityEngine.Audio;
public class AudioSound
{
public string name;
public AudioClip clip;
[Range(0f, 1f)]
public float volume;
[Range(.1f, 3f)]
public float pitch;
[HideInInspector]
public AudioSource source;
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: cd34753127bc0c44bb22ca73177fdd60
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: