it’s my block scripts look like
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Bloack : MonoBehaviour
{
[SerializeField] AudioClip Aesource;
Level level;
[SerializeField] GameObject blockSpark;
[SerializeField] int maxHits;
[SerializeField] int timesHit;
private void Start()
{
FirstSteap();
}
private void FirstSteap()
{
level = FindObjectOfType<Level>();
if (tag == "Yes")
{
level.CountBreakableBloacks();
}
}
private void OnCollisionEnter2D(Collision2D collision)
{
if (tag == "Yes")
{
HandleHit();
}
}
private void HandleHit()
{
timesHit++;
if (timesHit >= maxHits)
{
DestroyBlock();
}
}
private void DestroyBlock()
{
ForAudio();
Destroy(gameObject);
level.BlockDestoryed();
TriggerSparkVFX();
}
private void ForAudio()
{
FindObjectOfType<Game_date>().addToScore();
AudioSource.PlayClipAtPoint(Aesource, Camera.main.transform.position);
}
private void TriggerSparkVFX()
{
GameObject sparkles = Instantiate(blockSpark, transform.position, transform.rotation);
Destroy(sparkles, 2f);
}
}
but when i playing,if i destroy 1 block, all blocks will destroy in same time.
i want to check out what happened
so i did some change to Sceneloader’s scripts for stop load next scene with win
public void BlockDestoryed()
{
breakableBlocks–;
if(breakableBlocks <= 0)
{
// sceneloader.LoadNextScene();
}
}
then i go back to test,
blocks no longer destroy in same time
what is happening?