Hello! I’m working on a small Arkanoid clone and I’ve run into a little problem, that I’ve been stuck for a day. I’m semi-new to Unity, so I apologize in advance if there’s a simple solution to all of this. I am trying count how many blocks have been destroyed. I’ve set an int (count) to check the times the ball connects with the brick, and that seems to work. However, I’ve also set an int (brickCount) to try and increment the bricks being destroyed, but it never goes past one. I am only using one script, so that might be the problem? Here’s my code:
using UnityEngine;
using System.Collections;
public class Bricks : MonoBehaviour {
int count = 0;
int brickCount = 0;
void OnCollisionEnter2D(Collision2D other)
{
count++;
Debug.Log(count);
if (count >= 2)
{
Destroy(gameObject);
brickCount++;
Debug.Log("Destroyed " + brickCount + " brick.");
}
}
}
Thank you in advance!