fgm24/Assets/Scripts/Managers/GameManager.cs

98 lines
2.3 KiB
C#
Raw Normal View History

using System.Collections;
using System.Collections.Generic;
2024-02-04 09:52:47 +01:00
using System;
using UnityEngine;
2024-02-04 09:52:47 +01:00
using UnityEngine.Events;
2024-02-04 10:31:50 +01:00
using UnityEngine.SceneManagement;
public class GameManager : MonoBehaviour
{
2024-02-04 09:52:47 +01:00
public static GameManager Instance { get; private set; }
public Action OnPlayerDied;
2024-02-04 10:04:07 +01:00
private string penisSuriveTime = "";
2024-02-04 10:31:50 +01:00
public int Revives { get; private set; }
2024-02-04 11:13:51 +01:00
public GameObject ReviveParticleSystem;
2024-02-04 11:35:13 +01:00
public TMPro.TextMeshProUGUI ReviveText;
2024-02-04 09:52:47 +01:00
void Awake()
{
2024-02-06 14:06:21 +01:00
if (Instance != null)
2024-02-04 09:52:47 +01:00
{
2024-02-06 14:06:21 +01:00
Destroy(Instance);
2024-02-04 10:04:07 +01:00
}
2024-02-06 14:06:21 +01:00
Instance = this;
Revives = 1;
ReviveText.text = Revives + "x";
2024-02-04 09:52:47 +01:00
}
void Start()
{
2024-02-04 09:52:47 +01:00
}
2024-02-04 10:31:50 +01:00
public void playerDied(GameObject who)
2024-02-04 09:52:47 +01:00
{
2024-02-06 14:06:21 +01:00
Debug.Log($"{who.name} died");
2024-02-04 10:31:50 +01:00
if (Revives == 0)
2024-02-04 11:13:51 +01:00
{
2024-02-04 16:32:14 +01:00
AudioManager.Instance.StopAllAudio();
2024-02-04 11:13:51 +01:00
AudioManager.PlaySound("Game_Over_Jingle", Vector3.zero);
2024-02-04 10:31:50 +01:00
SceneManager.LoadScene(3);
2024-02-04 11:13:51 +01:00
}
else
{
2024-02-04 10:31:50 +01:00
Revives--;
2024-02-04 11:35:13 +01:00
ReviveText.text = Revives + "x";
2024-02-04 11:13:51 +01:00
Collider2D[] d = Physics2D.OverlapCircleAll(who.transform.position, 3f);
Debug.Log(d);
2024-02-04 10:31:50 +01:00
2024-02-04 11:13:51 +01:00
foreach (Collider2D c in d)
{
if (c.gameObject.CompareTag("Enemy"))
{
c.gameObject.GetComponent<HealthComponent>().TakeDamage(69420);
}
2024-02-04 10:31:50 +01:00
}
var g = who.GetComponent<HealthComponent>();
// heal
g.setMaxHealth(g.getMaxHealth(), true);
2024-02-07 21:47:09 +01:00
g.resetKillFlag();
2024-02-04 10:31:50 +01:00
// REVIVE SOUND HERE
2024-02-04 11:13:51 +01:00
AudioManager.PlaySound("Revive_SFX", who.transform.position);
RumbleManager.StartRumble(0, 0.3f, 0.1f, 3f);
RumbleManager.StartRumble(1, 0.3f, 0.1f, 3f);
2024-02-04 16:55:37 +01:00
GameObject go = Instantiate(ReviveParticleSystem, who.transform.position, Quaternion.identity);
ParticleSystem ps = go.GetComponent<ParticleSystem>();
ps.Play();
go.AddComponent<DestroyAfter>().Init(5f);
2024-02-04 10:31:50 +01:00
}
}
2024-02-04 11:35:13 +01:00
public void AddRevive()
{
2024-02-04 11:32:07 +01:00
Revives++;
2024-02-04 11:35:13 +01:00
ReviveText.text = Revives + "x";
2024-02-04 11:32:07 +01:00
}
2024-02-04 10:31:50 +01:00
public void setTime(string t)
{
2024-02-04 10:04:07 +01:00
penisSuriveTime = t;
}
// Update is called once per frame
void Update()
{
2024-02-04 09:52:47 +01:00
}
}