Question by
Shwiftyboi25 · Feb 03 at 01:03 PM ·
unity 2drpghealth
How do I make a game over and respawn system to work with my health system
Hi. I'm creating a top down RPG for a school project and I'm trying to make a respawn button so the player can respawn at 0,0. Only trouble is, i have no clue how to. I'm very new at unity and mostly self taught. I was wondering if I could get some help with this
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class healthSysyem : MonoBehaviour
{
public GameObject[] hearts;
public int life;
private bool dead;
void Update()
{
if (life < 1)
{
Destroy(hearts[0].gameObject);
}
else if (life < 2)
{
Destroy(hearts[1].gameObject);
}
else if (life < 3)
{
Destroy(hearts[2].gameObject);
}
if (dead == true)
{
Debug.Log("Oh no! Our player! it's broken");
Destroy(gameObject);
}
}
public void TakeDamage(int d)
{
life -= d;
if (life < 1)
{
dead = true;
}
}
}
Comment