Advertisement
Guest User

ExtrasScript

a guest
Oct 2nd, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEngine.SceneManagement;
  6.  
  7. public class ExtrasScript : MonoBehaviour
  8. {
  9. public static bool didFinish = false;
  10. public Button soundBtn;
  11. public Text btnTxt;
  12. public AudioClip sound1;
  13.  
  14. private AudioSource audioSource;
  15. private AudioSource themeSource;
  16.  
  17. public void BackMenu ()
  18. {
  19. if (!audioSource.isPlaying)
  20. {
  21. SceneManager.LoadScene ("Menu");
  22. }
  23. }
  24.  
  25. public void PlaySound ()
  26. {
  27. themeSource.Pause ();
  28. if (!audioSource.isPlaying)
  29. {
  30. audioSource.PlayOneShot (sound1);
  31. }
  32. }
  33.  
  34. void Start ()
  35. {
  36. audioSource = GetComponent<AudioSource> ();
  37. themeSource = GameObject.Find ("Music Player").GetComponent<AudioSource> ();
  38.  
  39.  
  40. if (didFinish == false)
  41. {
  42. soundBtn.interactable = false;
  43. btnTxt.text = "Complete Game to UNLOCK";
  44. }
  45. else if (didFinish == true)
  46. {
  47. soundBtn.interactable = true;
  48. btnTxt.text = "Play Sound";
  49. audioSource.Stop ();
  50. }
  51. }
  52.  
  53. void Update ()
  54. {
  55. if (didFinish == true)
  56. {
  57. if (audioSource.isPlaying)
  58. {
  59. btnTxt.text = "Sound is Playing";
  60. }
  61. else if (!audioSource.isPlaying)
  62. {
  63. themeSource.Play ();
  64. btnTxt.text = "Play Sound";
  65. }
  66. }
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement