Hi everyone, I have some problems with this lesson, and I need help. I can’t understand why my program is not working, because Debug program can’t find a mistakes…
On this screenshots you can see my script for bricks, and my unity console
And here my script too
using System.Collections;
using UnityEngine;
public class Brick3 : MonoBehaviour
{
public Sprite[] hitSprites;
public static int brickCount = 0;
private LevelManager levelManager;
private int timesHit;
private bool isBreakble;
// Use this for initialization
void Start()
{
levelManager = GameObject.FindObjectOfType<LevelManager>();
isBreakble = (this.tag == "breakble");
if (isBreakble) {
brickCount++;
print(brickCount);
}
timesHit = 0;
levelManager = GameObject.FindObjectOfType<LevelManager>();
}
void OnCollisionEnter2D(Collision2D col)
{
bool isBreakble = (this.tag == "Breakble");
if (isBreakble)
{HandleHits();}
else {}
}
void HandleHits() {
{
timesHit++;
int maxHits = hitSprites.Length + 1;
brickCount--;
print(brickCount);
if (timesHit == maxHits) {
brickCount--;
print(brickCount);
Destroy(gameObject);
}
else LoadSprites();
}
}
void LoadSprites()
{
int spriteIndex = timesHit - 1;
if (hitSprites[spriteIndex])
{
this.GetComponent<SpriteRenderer>().sprite = hitSprites[spriteIndex];
}
}
// TODO remove this method wheb we actually win!
void SimulateWin()
{
levelManager.LoadNextLevel();
}
}
indent preformatted text by 4 spaces