Advertisement
Guest User

Untitled

a guest
Jan 16th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. public class soundcontrol : MonoBehaviour {
  2. AudioSource theaudio ;
  3. public AudioClip clip1;
  4. public AudioClip clip2;
  5. public AudioClip clip3;
  6. AudioClip[] cliparray;
  7. int currentclip = -1;
  8. int maxclip = 0;
  9. bool isclip1null = false;
  10. bool isclip2null = false;
  11. bool isclip3null = false;
  12.  
  13. // Use this for initialization
  14. void Start () {
  15. }
  16.  
  17. // Update is called once per frame
  18. void Update () {
  19. maxclip = 0;
  20. if (clip1 != null) {
  21. isclip1null = true;
  22. cliparray [maxclip] = clip1;
  23. maxclip = maxclip + 1;
  24. }
  25. if (clip2 != null) {
  26. isclip2null = true;
  27. cliparray [maxclip] = clip2;
  28. maxclip = maxclip + 1;
  29. }
  30. if (clip3 != null) {
  31. isclip3null = true;
  32. cliparray [maxclip] = clip3;
  33. maxclip = maxclip + 1;
  34. }
  35. if (!theaudio.isPlaying) { // the error is here
  36. if (!((maxclip - 1) == -1)) {
  37. currentclip = currentclip + 1;
  38. if (currentclip > maxclip) {
  39. currentclip = 0;
  40. }
  41. if (!((maxclip - 1) == -1)) {
  42. theaudio.PlayOneShot (cliparray [currentclip]);
  43. }
  44. }
  45. }
  46. if ((maxclip - 1) == -1) {
  47. Debug.Log (" no clip attached ");
  48. }
  49. }
  50. }
  51.  
  52. // When the audio component has stopped playing, play otherClip
  53. using UnityEngine;
  54. using System.Collections;
  55.  
  56. public class ExampleClass : MonoBehaviour {
  57. public AudioClip otherClip;
  58. AudioSource audio;
  59.  
  60. void Start() {
  61. audio = GetComponent<AudioSource>();
  62. }
  63.  
  64. void Update() {
  65. if (!audio.isPlaying) {
  66. audio.clip = otherClip;
  67. audio.Play();
  68. }
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement