I’m having trouble getting it so that when you die, you get a gameover screen (which were the scene switches when you die) and i cant get it to work, here is what i have soo far
this is my gamemanager script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class GameManager : MonoBehaviour
{
public static GameManager gameManager { get; private set; }
public UnitHealth _playerHealth = new UnitHealth(100, 100);
void Awake()
{
if (gameManager != null && gameManager != this)
{
Destroy(this);
}
else
{
gameManager = this;
}
}
void Update()
{
if (GameManager.gameManager._playerHealth = GameManager.gameManager._playerHealth(0,0))
{
SceneManager.LoadScene(2);
}
}
}
and this is what i have in a script called PlayerBehavior (It has to do with health as well)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerBehavior : MonoBehaviour
{
[SerializeField] Healthbar _healthbar;
public InputActionReference takedamage;
public InputActionReference heal;
private PlayerInput playerInput;
private InputAction takedamageAction;
private void OnEnable()
{
takedamage.action.started += TakeDamage;
heal.action.started += Heal;
}
private void TakeDamage(InputAction.CallbackContext obj)
{
PlayerTakeDmg(20);
Debug.Log(GameManager.gameManager._playerHealth.Health);
}
private void Heal(InputAction.CallbackContext obj)
{
PlayerHeal(20);
Debug.Log(GameManager.gameManager._playerHealth.Health);
}
public void PlayerTakeDmg(int dmg)
{
GameManager.gameManager._playerHealth.DmgUnit(dmg);
_healthbar.SetHealth(GameManager.gameManager._playerHealth.Health);
}
private void PlayerHeal(int healing)
{
GameManager.gameManager._playerHealth.HealUnit(healing);
_healthbar.SetHealth(GameManager.gameManager._playerHealth.Health);
}
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.name == "EnemyBullet")
{
PlayerTakeDmg(20);
}
if (collision.gameObject.tag == "EnemyBullet")
{
PlayerTakeDmg(20);
}
}
}
i am also using the new unity input system