-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyTime.cs
52 lines (45 loc) · 1.69 KB
/
MyTime.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using UnityEngine;
public class MyTime : MonoBehaviour
{
public float timeLimit;
public static float timeLeft;
public bool gameStoped = false;
public GameObject player;
public GameObject timeClosingAnimation;
public GameObject circle;
// Start is called before the first frame update
void Start()
{
player = GameObject.FindGameObjectWithTag("Player");
circle = GameObject.FindGameObjectWithTag("Circle");
timeLeft = timeLimit;
}
// Update is called once per frame
void Update()
{
timeLeft -= Time.deltaTime;
if (timeLeft < .5 && player.GetComponent<SpriteRenderer>().enabled == true)
{
if (!gameStoped)
{
Instantiate(Resources.Load("particles/Crush Particle"), player.transform.position, Quaternion.identity);
player.GetComponent<SpriteRenderer>().enabled = false;
player.GetComponent<Collider2D>().enabled = false;
circle.GetComponent<Collider2D>().enabled = false;
timeClosingAnimation.SetActive(true);
if (PlayerPrefs.GetInt("SoundEnabled") == 1)
FindObjectOfType<AudioManager>().Play("CrushSound");
if (PlayerPrefs.GetInt("MusicEnabled", 1) == 1)
{
FindObjectOfType<AudioManager>().PauseWithFadeOut("GameMusic2", 2f);
FindObjectOfType<AudioManager>().PlayWithFadeIn("GameMusic", 5f);
}
gameStoped = true;
}
}
}
public void setTimeLeft( float timeLimit)
{
timeLeft = timeLimit;
}
}