-
Notifications
You must be signed in to change notification settings - Fork 0
/
DeathCheck.cs
27 lines (23 loc) · 937 Bytes
/
DeathCheck.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class DeathCheck : MonoBehaviour {
float vertExtent;
public AudioClip sound;
AudioSource audioSource;
void Start () {
vertExtent = Camera.main.orthographicSize;
PlayerPrefs.SetInt("currentScore", 0);
GameObject.Find("Score").GetComponent<Text>().text = PlayerPrefs.GetInt("currentScore").ToString();
GameObject.Find("Best Score").GetComponent<Text>().text = PlayerPrefs.GetInt("bestScore", 0).ToString();
audioSource = GameObject.Find("Audio").GetComponent<AudioSource>();
}
void Update () {
if (Camera.main.transform.position.y - vertExtent > transform.position.y)
{
PlayerPrefs.SetInt("deaths", PlayerPrefs.GetInt("deaths") + 1);
audioSource.PlayOneShot(sound);
SceneManager.LoadScene("Death");
}
}
}