I am looking for a way where on2dcollision health is removed, similar to that of diep.io any references or personal solutions would be very appreciated. Thanks.
GM Script:
using UnityEngine;
using System.Collections;
using UnityStandardAssets.ImageEffects;
public class GameMaster : MonoBehaviour {
public static GameMaster gm;
void Awake () {
if (gm == null) {
gm = GameObject.FindGameObjectWithTag ("GM").GetComponent<GameMaster>();
}
}
public Transform playerPrefab;
public Transform spawnPoint;
public float spawnDelay = 2;
public Transform spawnPrefab;
public IEnumerator RespawnPlayer () {
GetComponent<AudioSource>().Play ();
yield return new WaitForSeconds (spawnDelay);
Instantiate (playerPrefab, spawnPoint.position, spawnPoint.rotation);
GameObject clone = Instantiate (spawnPrefab, spawnPoint.position, spawnPoint.rotation) as GameObject;
Destroy (clone, 3f);
}
public static void KillPlayer (Player player) {
Destroy (player.gameObject);
gm.StartCoroutine (gm.RespawnPlayer());
}
public static void KillEnemy (Enemy enemy) {
Destroy (enemy.gameObject);
}
}
Player/Enemy Script:
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour {
[System.Serializable]
public class PlayerStats {
public int Health = 100;
}
public PlayerStats playerStats = new PlayerStats();
public int fallBoundary = -20;
void Update () {
if (transform.position.y <= fallBoundary)
DamagePlayer (9999999);
}
public void DamagePlayer (int damage) {
playerStats.Health -= damage;
if (playerStats.Health <= 0) {
GameMaster.KillPlayer(this);
}
}
}