Bricks not working in WebGL

Hi, I’ve got a problem this night with web GL. The Block Breaker Works at Unity 4.6, then i upgrade at Unity 5 and it Works well, you can play destroying blocks and with sounds, but the problem is when i build to Web GL. I don’t know why 'cause you can play but the bricks aren’t destroyed when the ball hits them.
I’ve been more than three hours here, ending at 3 am, but i can’t think more. My brain needs to sleep.

Ok, no one has helped, so i think it’s because you don’t know how to help me… i will try to show you the code of the bricks:

using UnityEngine;
using System.Collections;

public class Brick : MonoBehaviour {

private LevelManager levelManager;
private int timesHit;
private bool isBreakable; 

public AudioClip crack;
public static int BreakableCount;
public Sprite[] hitSprites;
public GameObject smoke;

void Awake (){
	BreakableCount = 0;
}

// Use this for initialization
void Start () {
	isBreakable = (this.tag == "Breakable");
	if (isBreakable) {
		BreakableCount ++;
		print (BreakableCount);
	}
	timesHit = 0;
	levelManager = GameObject.FindObjectOfType <LevelManager> ();
}

// Update is called once per frame
void Update () {

}


   // I've put OnCollisionExit2D to solve a problem with the sound
    void OnCollisionExit2D (Collision2D col){
	AudioSource.PlayClipAtPoint (crack, transform.position, 1.0f);
	if(isBreakable){
		HandleHits ();
	}
}

void HandleHits (){
	timesHit ++;
	int maxHits = hitSprites.Length + 1;
	if (timesHit >= maxHits) {
		BreakableCount --;
		levelManager.BrickDestroyed ();
		SmokePuff ();
		Destroy (gameObject);
	} else {
		LoadSprites ();
	}
}

void SmokePuff (){
        GameObject smokePuff = Instantiate(smoke, gameObject.transform.position, Quaternion.identity) as GameObject;
        smokePuff.GetComponent<ParticleSystem>().startColor = gameObject.GetComponent<SpriteRenderer>().color;
}

void LoadSprites (){
	int spriteIndex = timesHit - 1;
	if (hitSprites [spriteIndex]) {
		this.GetComponent<SpriteRenderer> ().sprite = hitSprites [spriteIndex];
	}
}

// TODO Remove this method once we can actualy win
void SimulateWin(){
	levelManager.LoadNextLevel ();
}

}

The problem is that with my computer it works (at unity 4.6 and at unity 5, but not when i “Build and Run” the game with Web GL).
Please, try to help me.

Hi Jaume,

I’ve just got your message, and I’m sorry that nobody has helped you yet. Next time please feel free to post your question on Udemy in the Q&A section of the Unity course, too. I usually reply there within 24h from Mondays to Fridays, and sometimes also at the weekends.

Regarding your issue, I assume this could have to do with the tags. Some students noticed that their tags broke when they imported their Unity 4 projects to Unity 5. Deleting, recreating and readding them usually fixed the issue.

Does that work for you, too?

ok, i’ve tried to see the tags, & yes, the bricks didn’t have the tag of breakable. But I set this & tryed and it doesn’t work well yet. I’ve tried to set the maxHits as public, to set from the Unity and see how it works, but the problem is still there. The game works well, but when i Build & Run at Web GL the bricks aren’t destroyed.
Reading the scripts all seems to be good, I don’t know what is happening. Do you want here the scripts of the Bricks and the levelManager?

Since Jaume and I already solved this issue on Udemy, I thought I could share the solution here for other students. The issue were indeed the tags but it wasn’t that obvious.

  1. Set all your tags on your game objects to default.
  2. Click on Add tag … to get to the tag list.
  3. Remove all tags from the list, which only works if none of these tags are used by any game objects.
  4. Restart Unity and go back to the list, which should now be empty.
  5. If it’s completely empty, recreate your tags.
  6. Assign your tags to your game objects.

Now the tags should work properly in your WebGL game.

Privacy & Terms