I am a new young programmer that is working on a game, and i ve faced this issue since a day and i cant find a solution for it. So I came here seeking for help.
I made a script for damaging both the player and the enemy at the same time:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Damageable : MonoBehaviour {
public float maxHealth;
private float health;
public Image healthBar;
void Start()
{
health = maxHealth;
}
void Update()
{
if (health > maxHealth)
{
health = maxHealth;
}
if (health <= 0)
{
Destroy(gameObject);
}
}
public void Damage ( int damageValue)
{
health -= damageValue;
healthBar.fillAmount = health / maxHealth;
Debug.Log(health);
}
}
It works properly, but i want the scene to reload on player death. i tried adding:
Application.LoadedLevel (Application.loadedLevel);
but now not only when the player dies the scene reloads, but also when the enemy is killed.
I want to find a way to specify that only only when the player dies the scene reloads. It will be great if any of u pro coders will help me.
P.S. dont mind the damageValue thingies cuz they are in another script.