-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScoreManager.cs
More file actions
68 lines (58 loc) · 1.57 KB
/
ScoreManager.cs
File metadata and controls
68 lines (58 loc) · 1.57 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
using System.Collections;
using UnityEngine.UI;
using UnityEngine;
public class ScoreManager : MonoBehaviour {
public Text scoreText;
public Text highScoreText;
public float scoreCount;
public float highScoreCount;
public float pointsPerSecond;
public float pointsPerSecondStore;
public bool scoreIncreasing;
// Use this for initialization
void Start () {
if (PlayerPrefs.HasKey("HighScore"))
{
highScoreCount = PlayerPrefs.GetFloat("HighScore");
}
pointsPerSecondStore = pointsPerSecond;
}
// Update is called once per frame
void Update () {
if (scoreIncreasing)
{
scoreCount += pointsPerSecond * Time.deltaTime;
}
if (scoreCount >= 500)
{
pointsPerSecond = 8;
}
if (scoreCount >= 1000)
{
pointsPerSecond = 10;
}
if (scoreCount >= 2000)
{
pointsPerSecond = 12;
}
if (scoreCount >= 2500)
{
pointsPerSecond = 14;
}
if (scoreCount >= 3000)
{
pointsPerSecond = 16;
}
if (scoreCount> highScoreCount)
{
highScoreCount = scoreCount;
PlayerPrefs.SetFloat("HighScore", highScoreCount);
}
scoreText.text = "Score: " + Mathf.Round( scoreCount);
highScoreText.text = "High Score: " + Mathf.Round (highScoreCount);
}
public void AddScore(int pointsToAdd)
{
scoreCount += pointsToAdd;
}
}