Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class MusicPlayer : MonoBehaviour
- {
- public AudioClip[] clips;
- public AudioSource audioSource;
- public bool playrandom;
- public bool pause;
- public float timer;
- void Start()
- {
- timer = 0.0f;
- audioSource = FindObjectOfType<AudioSource>();
- audioSource.loop = false;
- }
- protected AudioClip PlayClip()
- {
- return clips[Random.Range(0, clips.Length)];
- }
- void Update()
- {
- if (playrandom == true)
- {
- audioSource.clip = PlayClip();
- if (pause == false)
- {
- audioSource.Play();
- }
- }
- else if (playrandom == false)
- {
- }
- if (Input.GetKeyDown(KeyCode.F1))
- {
- if (pause == true)
- {
- pause = false;
- audioSource.Play();
- }
- else if (pause == false)
- {
- pause = true;
- audioSource.Pause();
- }
- }
- if (Input.GetKeyDown(KeyCode.F2))
- {
- }
- if (Input.GetKeyDown(KeyCode.F3))
- {
- }
- if (Input.GetKeyDown(KeyCode.F4))
- {
- playrandom = true;
- }
- if (playrandom == true)
- {
- if (timer <= 0.0f || timer >= 0.0f)
- {
- timer += Time.deltaTime;
- }
- if (timer >= 0.5f)
- {
- timer = 0.0f;
- playrandom = false;
- }
- }
- }
- public void PlayClips()
- {
- playrandom = false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement