1
0
This repository has been archived on 2024-09-03. You can view files and clone it, but cannot push or open issues or pull requests.
System-Purge/Assets/Sounds/BackgroundMusic.cs
2016-01-30 22:45:03 -05:00

38 lines
849 B
C#

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class BackgroundMusic : MonoBehaviour {
public AudioClip[] mClips;
int currSong;
int nextSong;
// Use this for initialization
void Start () {
currSong = 0;
GetComponent<AudioSource> ().clip = mClips [currSong];
GetComponent<AudioSource> ().Play ();
}
// Update is called once per frame
void Update () {
AudioSource audio = GetComponent<AudioSource> ();
if (Input.GetKeyDown (KeyCode.Minus)) {
audio.Stop ();
nextSong = -1;
}
if (Input.GetKeyDown (KeyCode.Equals)) {
audio.Stop ();
nextSong = 1;
}
if (!audio.isPlaying) {
currSong += nextSong;
if (currSong == mClips.Length - 1)
currSong = 0;
if (currSong < 0)
currSong = mClips.Length - 1;
audio.clip = mClips [currSong];
audio.Play ();
}
}
}