Hi. I was up to course 68/69 when I noticed that my next level wasn’t loading because the breakable object count was not decreasing anymore. I’m not sure what to do at this point and I am in need of help.
Here are the scripts I think are related to the problem.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Level : MonoBehaviour
{
// parameters
[SerializeField] int breakableTargets;
// cached reference
SceneLoader sceneLoader;
private void Start()
{
sceneLoader = FindObjectOfType<SceneLoader>();
}
public void CountBreakableTargets()
{
breakableTargets++;
}
public void TargetDestroyed()
{
breakableTargets--;
if (breakableTargets <= 0)
{
sceneLoader.LoadNextScene();
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Target : MonoBehaviour
{
[SerializeField] AudioClip breakSound;
// cached reference
Level level;
private void Start()
{
level = FindObjectOfType<Level>();
level.CountBreakableTargets();
}
private void OnCollisionEnter2D(Collision2D collision)
{
DestroyTarget();
}
private void DestroyTarget()
{
AudioSource.PlayClipAtPoint(breakSound, (Camera.main.transform.position));
Destroy(gameObject);
FindObjectOfType<GameStatus>().AddToScore();
}
}
I fixed it by calling level.TargetDestroyed(); in my DestroyTarget method
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.