I want to make a Breakout game in Unity. I made a lot of the functions work except the "count" function. I want the "count"function to tell the user how many bricks are left. Every time a brick (gameObject) gets destroyed, the int variable "bricks" will decrease by one. The problem I have is that it only updates once (from 104 to 103) then stops updating. Here is my script:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Spawner : MonoBehaviour {
public int bricks = 104;
public Text triggerText;
void Start(){
triggerText.text = "Bricks: "+bricks;
}
public void OnCollisionEnter(){
DestroyBrick ();
}
public void DestroyBrick(){
bricks--;
Destroy (gameObject);
triggerText.text = "Bricks: "+bricks;
}
edit: I forgot to mention that I added this script to my Brick gameObjects (104 of them) in order for them to break when collided.