Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- using UnityEngine.UI;
- public class cprMaster : MonoBehaviour
- {
- public Text feedback;
- public Text scoreLabel;
- public Text readySetGo;
- public AudioSource audio;
- public AudioSource rsgAudio;
- public AudioSource musicAudio;
- public AudioClip tap;
- public AudioClip music;
- public AudioClip ready;
- public AudioClip set;
- public AudioClip go;
- public GameObject playAgain;
- private bool started = false;
- public bool ended = false;
- public float timeAtLastTap;
- public int score;
- public int scoreMult;
- // Use this for initialization
- private void Start()
- {
- rsgAudio = readySetGo.GetComponent<AudioSource>();
- audio = GameObject.FindGameObjectWithTag("Compress").GetComponent<AudioSource>();
- musicAudio = GetComponent<AudioSource>();
- timeAtLastTap = Time.fixedTime;
- StartCoroutine(GetReady());
- }
- private void FixedUpdate()
- {
- if(Time.time - timeAtLastTap > 0.65)
- {
- scoreMult = 0;
- //feedback.text = "bad! You missed a beat!";
- timeAtLastTap = Time.fixedTime - 0.05f;
- }
- scoreLabel.text = "SCORE: " + score.ToString();
- }
- public void Tap()
- {
- audio.PlayOneShot(tap);
- float diff = Time.fixedTime - timeAtLastTap;
- if(diff > 0.55f && diff < 0.65)
- {
- if(started)
- {
- scoreMult++;
- score += 1 * scoreMult;
- feedback.text = "x" + scoreMult.ToString() + " Multiplier!";
- }
- }
- else
- {
- scoreMult = 0;
- if(started)
- {
- feedback.text = "You missed a beat!"; //+ diff.ToString() ;
- }
- }
- timeAtLastTap = Time.fixedTime;
- }
- public void PlayAgain()
- {
- SceneManager.LoadScene(sceneNames.cpr.ToString());
- }
- private IEnumerator GetReady()
- {
- yield return new WaitForSeconds(6f);
- readySetGo.text = "READY";
- rsgAudio.PlayOneShot(ready);
- yield return new WaitForSeconds(2f / 3f);
- readySetGo.text = "GET SET";
- rsgAudio.PlayOneShot(set);
- yield return new WaitForSeconds(2f / 3f);
- readySetGo.text = "GO!";
- rsgAudio.PlayOneShot(go);
- musicAudio.Stop();
- musicAudio.PlayOneShot(music);
- started = true;
- yield return new WaitForSeconds(2f / 3f);
- readySetGo.gameObject.SetActive(false);
- scoreLabel.gameObject.SetActive(true);
- yield return new WaitForSeconds(13 + (5f + 1f / 3f));
- GameObject.FindGameObjectWithTag("Compress").SetActive(false);
- readySetGo.gameObject.SetActive(true);
- scoreLabel.gameObject.SetActive(false);
- feedback.gameObject.SetActive(false);
- readySetGo.text = "FINAL SCORE: " + score.ToString() + " \n WELL DONE!";
- Invoke("loadNextScene", 3.0f);
- started = false;
- ended = true;
- yield return new WaitForSeconds(2f);
- //playAgain.gameObject.SetActive(true);
- }
- private void loadNextScene()
- {
- PlayerPrefs.SetInt(sceneNames.bleeding.ToString(), 1);
- SceneManager.LoadScene(sceneNames.LevelSelecter.ToString());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement