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
using Assets.Scripts.API;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace Assets.Scripts
{
public class Player : MonoBehaviour
{
private Transform _pos;
private float _blinkTimer = 0f;
private int _blinkCount = 0;
public int Score = 0;
public int Battery = 100;
public int Progression = 0;
public bool IsBlinking = false;
public int NbVials = 0;
void Start()
{
_pos = GetComponent<Transform>();
}
void Update()
{
var newPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
newPos.z = -1;
_pos.position = Vector3.Lerp(_pos.position, newPos, 10*Time.deltaTime);
if (IsBlinking)
Blink();
if (Battery < 12)
{
if (PlayerPrefs.GetInt("highscore") < Score)
PlayerPrefs.SetInt("highscore", Score);
PlayerPrefs.SetInt("lastscore", Score);
SceneManager.LoadScene("GameOver");
}
if (Progression == 25)
{
Score += 200;
}
}
public void Blink()
{
_blinkTimer += Time.deltaTime;
if (_blinkTimer > .16f)
{
GetComponent<SpriteRenderer>().enabled = !GetComponent<SpriteRenderer>().enabled;
_blinkCount++;
_blinkTimer = 0f;
}
if (_blinkCount != 7) return;
_blinkCount = 0;
_blinkTimer = 0f;
GetComponent<BoxCollider2D>().enabled = true;
IsBlinking = false;
}
public void SetBlinking()
{
GetComponent<BoxCollider2D>().enabled = false;
GetComponent<SpriteRenderer>().enabled = false;
IsBlinking = true;
}
}
}