Advertisement
Guest User

Untitled

a guest
Apr 19th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.91 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.SceneManagement;
  5. using UnityEngine.UI;
  6.  
  7. public class cprMaster : MonoBehaviour
  8. {
  9. public Text feedback;
  10. public Text scoreLabel;
  11. public Text readySetGo;
  12.  
  13. public AudioSource audio;
  14. public AudioSource rsgAudio;
  15. public AudioSource musicAudio;
  16.  
  17. public AudioClip tap;
  18. public AudioClip music;
  19. public AudioClip ready;
  20. public AudioClip set;
  21. public AudioClip go;
  22.  
  23. public GameObject playAgain;
  24.  
  25. private bool started = false;
  26. public bool ended = false;
  27. public float timeAtLastTap;
  28. public int score;
  29. public int scoreMult;
  30.  
  31. // Use this for initialization
  32. private void Start()
  33. {
  34. rsgAudio = readySetGo.GetComponent<AudioSource>();
  35. audio = GameObject.FindGameObjectWithTag("Compress").GetComponent<AudioSource>();
  36. musicAudio = GetComponent<AudioSource>();
  37. timeAtLastTap = Time.fixedTime;
  38. StartCoroutine(GetReady());
  39. }
  40.  
  41. private void FixedUpdate()
  42. {
  43. if(Time.time - timeAtLastTap > 0.65)
  44. {
  45. scoreMult = 0;
  46. //feedback.text = "bad! You missed a beat!";
  47. timeAtLastTap = Time.fixedTime - 0.05f;
  48. }
  49. scoreLabel.text = "SCORE: " + score.ToString();
  50. }
  51.  
  52. public void Tap()
  53. {
  54. audio.PlayOneShot(tap);
  55. float diff = Time.fixedTime - timeAtLastTap;
  56. if(diff > 0.55f && diff < 0.65)
  57. {
  58. if(started)
  59. {
  60. scoreMult++;
  61. score += 1 * scoreMult;
  62. feedback.text = "x" + scoreMult.ToString() + " Multiplier!";
  63. }
  64. }
  65. else
  66. {
  67. scoreMult = 0;
  68. if(started)
  69. {
  70. feedback.text = "You missed a beat!"; //+ diff.ToString() ;
  71. }
  72. }
  73. timeAtLastTap = Time.fixedTime;
  74. }
  75.  
  76. public void PlayAgain()
  77. {
  78. SceneManager.LoadScene(sceneNames.cpr.ToString());
  79. }
  80.  
  81. private IEnumerator GetReady()
  82. {
  83. yield return new WaitForSeconds(6f);
  84. readySetGo.text = "READY";
  85. rsgAudio.PlayOneShot(ready);
  86.  
  87. yield return new WaitForSeconds(2f / 3f);
  88. readySetGo.text = "GET SET";
  89. rsgAudio.PlayOneShot(set);
  90.  
  91. yield return new WaitForSeconds(2f / 3f);
  92. readySetGo.text = "GO!";
  93. rsgAudio.PlayOneShot(go);
  94. musicAudio.Stop();
  95. musicAudio.PlayOneShot(music);
  96. started = true;
  97. yield return new WaitForSeconds(2f / 3f);
  98. readySetGo.gameObject.SetActive(false);
  99. scoreLabel.gameObject.SetActive(true);
  100.  
  101. yield return new WaitForSeconds(13 + (5f + 1f / 3f));
  102. GameObject.FindGameObjectWithTag("Compress").SetActive(false);
  103. readySetGo.gameObject.SetActive(true);
  104. scoreLabel.gameObject.SetActive(false);
  105. feedback.gameObject.SetActive(false);
  106. readySetGo.text = "FINAL SCORE: " + score.ToString() + " \n WELL DONE!";
  107.  
  108. Invoke("loadNextScene", 3.0f);
  109.  
  110. started = false;
  111. ended = true;
  112.  
  113. yield return new WaitForSeconds(2f);
  114. //playAgain.gameObject.SetActive(true);
  115. }
  116.  
  117. private void loadNextScene()
  118. {
  119. PlayerPrefs.SetInt(sceneNames.bleeding.ToString(), 1);
  120. SceneManager.LoadScene(sceneNames.LevelSelecter.ToString());
  121. }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement