How I can detect when particular gameobject with tag Player gets deleted so I can show an game over message? Please help in c# as I’m learning that.
EDIT: Here is the working version of the script. Edited and tested, working fine for me.
using UnityEngine;
using System.Collections;
public class Valikko : MonoBehaviour
{
GameObject Pallo;
int bricksLeft;
bool destroyedAllBricks = false;
void Start ()
{
Pallo = GameObject.FindGameObjectWithTag("Player");
}
void Update ()
{
GameObject[] bricks = GameObject.FindGameObjectsWithTag("Brick");
bricksLeft = bricks.Length;
if(Input.GetKeyDown(KeyCode.A))
{
if(bricks.Length > 0)
Destroy (bricks[bricks.Length - 1]);
}
if(bricksLeft <= 0)
{
destroyedAllBricks = true;
}
}
void OnGUI ()
{
if(Pallo == null)
{
GUI.Box (new Rect (0,60,200,25),"Game Over!");
}
if(destroyedAllBricks)
{
GUI.Box (new Rect (0,30,200,25),"All bricks destroyed!");
}
else
{
GUI.Box (new Rect(0,30,200,25),"Bricks remaining :" + bricksLeft);
GUI.Box (new Rect (0,0,200,25), "CrazyBricks 3D v0.2");
GUI.Box (new Rect (Screen.width -300,0,300,25), "Broken Signal Entertainment (c) 2013");
}
}
}