Hey guys,
I’m working on a simple little space game where you control a ship and mine asteroids. I’ve got everything working, but for some reason, when I build the game to Webplayer, the collision between my drill head and the asteroids isn’t working as intended.
I don’t think it’s a coding problem, as it works with everything except Webplayer. Anyone got any ideas?
Here’s the bit of code that’s breaking:
void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.layer == 8)
{
GameObject.Find("Player").GetComponent<MiningController>().Attached(collision);
GameObject.Find("Player").GetComponent<MiningController>().DestroyDrill(true);
}
else
{
GameObject.Find("Player").GetComponent<MiningController>().DestroyDrill(false);
}
}
When the drill collides with something, if it’s an asteroid, attach it to the asteroid. Regardless of whether it’s an asteroid or not, destroy it afterwards.
In editor, PC build, and WebGL builds, this functions perfectly. But in webplayer (not WebGL, the regular web player), the drill just bounces off asteroids, doesn’t attach, and doesn’t get destroyed. It’s like the function isn’t being called on asteroid collision, though it still works if the drill hits a wall.
Webplayer build: https://dl.dropboxusercontent.com/u/79481448/SpaceThing.html
WebGL build: https://dl.dropboxusercontent.com/u/79481448/SpaceThing/ShipThing.html
EDIT: I’ve narrowed the problem down a little bit. The function is being called, it’s just hitting an error or something at the “if (collision.gameObject.layer == 8)”, and not continuing through the rest of the function. Why would being in the web player cause an error there?