-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayerScript.cs
More file actions
44 lines (39 loc) · 1.34 KB
/
Copy pathPlayerScript.cs
File metadata and controls
44 lines (39 loc) · 1.34 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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerScript : MonoBehaviour
{
public float health = 100;
public bool isDead;
[SerializeField] private TimeManager tManager;
[SerializeField] private TMPro.TMP_Text healthText;
private GameEventsManagerScript GameEventsManager;
// Start is called before the first frame update
void Awake()
{
GameEventsManager = GameObject.Find("GameEventsManager").GetComponent<GameEventsManagerScript>();
}
// Update is called once per frame
void Update()
{
health = Mathf.Clamp(health, 0, 100);
healthText.text = "+"+health.ToString();
if(health <= 0 && !isDead)
{
Die();
GameEventsManager.OnGameOver?.Invoke();
}
}
void Die()
{
isDead = true;
string oldString = PlayerPrefs.GetString("Bat4BatsData", "");
PlayerPrefs.SetString("Bat4BatsData", oldString + (tManager.totalTimer - tManager.prepTime).ToString("F2") + ";" + System.DateTime.Now.ToString() +
";" + PlayerPrefs.GetInt("RecoveryStage") + ";" + PlayerPrefs.GetInt("SpawnRange") + "~");
Debug.Log(PlayerPrefs.GetString("Bat4BatsData"));
}
public void Damage(int val)
{
health -= val;
}
}