-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnvironmentManager.cs
More file actions
79 lines (66 loc) · 1.71 KB
/
EnvironmentManager.cs
File metadata and controls
79 lines (66 loc) · 1.71 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using UnityEngine.UI;
using System.Linq;
public class EnvironmentManager : MonoBehaviour
{
public GameObject newStreet;
public GameObject currentStreet;
private GameObject _oldStreet;
public GameObject GameOver;
private int counter;
public int score;
public Text user_score;
private float timeRemaining;
public float minutes;
public float seconds;
void Start()
{
timeRemaining = 0;
}
void Update() //silinebilir
{
timeRemaining += Time.deltaTime;
if (timeRemaining > 0)
{
minutes = Mathf.Floor(timeRemaining / 60);
seconds = Mathf.Floor(timeRemaining % 60);
}
}
void OnTriggerEnter(Collider other)
{
if(other.tag == "Start")
{
if(_oldStreet != null)
{
Destroy(_oldStreet);
} else {
Destroy(GameObject.Find("MainScene"));
}
}
else if(other.tag == "Middle")
{
SpawnLevel();
}
}
void SpawnLevel()
{
_oldStreet = currentStreet;
currentStreet = (GameObject) Instantiate(newStreet,currentStreet.transform.GetChild(0).position, Quaternion.identity);
counter++;
if(counter == 1)
{
Time.timeScale = 0;
GameOver.SetActive(true);
score = GameScore();
PlayerPrefs.SetInt("Score", score);
user_score.text = score.ToString();
}
}
public int GameScore()
{
return 6000 / System.Convert.ToInt32(minutes * 60 + seconds);
}
}