I had completed Blockbreaker and have a good 6 level game made and added the “smoke” effect and as a VERY new person to this I also added fire works to the “Win” screen. Unfortunately while doing this something happened and everything in the program (game) works except bricks will not destroy. Meaning they go through the motions of hit one, hit two with sprite changes but the item now is an invincible brick. I have gone back and re wrote the brick script, the level manager script and uninstalled smoke prefab and reinstalled it but to no avail . Bricks will not go away. HELP!!
Thank you
P.S. be kind as I am VERY new at this.
Hi Michael,
Could you post your code from the Brick script please.
See also;
- Forum User Guides : How to apply code formatting within your post
I was trying everything and tried opening and seeing if it would work with Unity 2017, didn’t work but now I cannot open in 5.6
using UnityEngine;
using System.Collections;
public class Bricked
: MonoBehaviour {
public AudioClip crack;
public Sprite[] hitSprites;
public static int breakableCount = 0;
public GameObject smoke;
private int timesHit;
private LevelManager levelManager;
private bool isBreakable;
// Use this for initialization
void Start () {
isBreakable = (this.tag == "Breakable");
// Keep track of breakable bricks
if (isBreakable) {
breakableCount++;
}
timesHit = 0;
levelManager = GameObject.FindObjectOfType<LevelManager>();
}
// Update is called once per frame
void Update () {
}
void OnCollisionEnter2D (Collision2D col) {
AudioSource.PlayClipAtPoint (crack, transform.position, 0.8f);
if (isBreakable) {
HandleHits();
}
}
void HandleHits () {
timesHit++;
int maxHits = hitSprites.Length + 1;
if (timesHit >= maxHits) {
breakableCount--;
levelManager.BrickDestoyed();
PuffSmoke();
Destroy(gameObject);
} else {
LoadSprites();
}
}
void PuffSmoke () {
GameObject smokePuff = Instantiate (smoke, transform.position, Quaternion.identity) as GameObject;
smokePuff.GetComponent<ParticleSystem>().startColor = gameObject.GetComponent<SpriteRenderer>().color;
}
void LoadSprites () {
int spriteIndex = timesHit - 1;
if (hitSprites[spriteIndex] != null) {
this.GetComponent<SpriteRenderer>().sprite = hitSprites[spriteIndex];
} else {
Debug.LogError ("Brick sprite missing");
}
}
// TODO Remove this method once we can actually win!
void SimulateWin () {
levelManager.LoadNextLevel();
}
}
Hi,
OK, so there may be some API differences between the Unity versions. Unity typically prompts whether you want to upgrade the project to the newer version and asks if you have a back up.
So, first question…
Do you have a back up prior to opening it in Unity 2017?
If not, had you done anything different to the course version? If not, you could grab a copy of the completed course version at various steps through the lectures from Github.
If you had made you own changes and want to keep them, is there any reason you cannot continue, from your perspective with Unity 2017?
Next question…
When you say it doesn’t work, what exactly is happening, is it only the bricks not getting destroyed or are there different issues depending on which version of Unity you try to use?
If its a case of the bricks not being destroyed and you want to continue with Unity 2017 that gives us a place to start from. If there are other errors being displayed in the console though it would be useful to know what they are or perhaps provide a screen shot.
If it is simply the bricks not disappearing when destroyed, we could do with putting a Debug.Log
statement in the HandleHits
method to see if the code you are expecting to be run actually is, perhaps starting just at the top of that method.
If this doesn’t output anything, then we can move back to the OnCollisionEnter2D
method and pop a Debug.Log
statement within the if
statement. Does anything get output not? If not, it would be worth checking that the bricks in the scene have the correct tags and also their prefabs.
Let me know what you find out from the above, or give me a shout back if anything above doesn’t make sense.
Hi thanks for taking the time for this,
I was just coming onto this question to say I solved it. (Finally).
I thought I had a back up but cannot find it. I had the issue before trying it in a newer version. I am reworking in 2017 version and keeping that. Since that part of the course is finished, I downloaded the “course brick.cs script” and used that as a way to try and fix it but to no avail. Finally I had already put a debug in it and found the issue was with Level Manager script that added a line in “Public Void Brick Destroyed” line. I deleted that line and it worked.
In 2017 version I still have to add script to prefabs etc.
Michael
Hi Michael,
Glad to hear your are moving forwards with this again.
Regarding that line, I believe it just needs the space removing, as it was a method definition, e.g.;
public void BrickDestroyed()
{
// do stuff here
}
You could obviously jump back to a previous version for the next section of the course, which may make it easier regarding any API differences.