Hey everyone, one of my students is experiencing a strange bug. When in Unity, you can complete a level and a proper scene change occurs. However, once built for WebGL and uploaded to itch.io, the Scene change does not occur any longer when all of the bricks are destroyed. No exceptions are thrown. Here’s a link to her game: https://cinn-senpai.itch.io/ephem-knight
And the relevant scripts:
Brick:
public AudioClip crack;
public Sprite[] hitSprites;
public static int breakableCount = 0;
private int timesHit;
private LevelManager levelManager;
private bool isBreakable;
// Use this for initialization
void Start () {
isBreakable = (this.tag == "Breakable");
if (isBreakable)
{
breakableCount++;
}
print(breakableCount);
timesHit = 0;
levelManager = GameObject.FindObjectOfType<LevelManager>();
}
void OnCollisionEnter2D (Collision2D col)
{
AudioSource.PlayClipAtPoint(crack, transform.position);
if (isBreakable)
{
HandleHits();
}
}
void HandleHits()
{
int maxHit = hitSprites.Length + 1;
timesHit++;
if (timesHit >= maxHit)
{
breakableCount--;
levelManager.brickDestroyed();
Destroy(gameObject);
}
else
{
LoadSprites();
}
}
void LoadSprites()
{
int spriteIndex = timesHit - 1;
if (hitSprites[spriteIndex])
{
this.GetComponent<SpriteRenderer>().sprite = hitSprites[spriteIndex];
}
}
void SimulateWin()
{
levelManager.LoadNextLevel();
}
LevelManager:
public LevelManager levelManager;
private Ball ball;
private Vector3 balpos;
private Vector2 balVec;
private void Start (){
ball = GameObject.FindObjectOfType<Ball>();
if (ball)
{
balpos = ball.transform.position;
balVec = ball.GetComponent<Rigidbody2D>().velocity;
}
}
public void ResetBall()
{
Debug.Log("Ball Reset");
balpos = ball.transform.position;
balVec = ball.GetComponent<Rigidbody2D>().velocity;
ball.Loselife();
}
public void LoadLevel(string name)
{
SceneManager.LoadScene(name);
}
public void LoadNextLevel ()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
}
public void brickDestroyed()
{
if (Brick.breakableCount <= 0)
{
LoadNextLevel();
}
}
LoseCollider:
private LevelManager levelManager;
public int lives = 3;
public Text text;
void Start()
{
levelManager = FindObjectOfType<LevelManager>();
}
// when ball hits lose collider goes to game over
void OnTriggerEnter2D(Collider2D trigger)
{
lives--;
Debug.Log("Life lost");
text.text = lives.ToString();
if (lives <= 0)
{
lives = 3;
levelManager.LoadLevel("Lose");
}
else
{
levelManager.ResetBall();
}
}
Build Settings: