Kind of stuck with tags Lost the SFX Sparkles Effect and the Counter isn’t working anymore, and for some reason the left side of my game’s unbreakable blocks are just passed through by the ball here is my code and I can’t find whats wrong.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Block : MonoBehaviour
{
[SerializeField] AudioClip breakSound; //Create audio source
[SerializeField] GameObject blockSparklesVFX; // searlizing for the sparkle effect
//Cache Reference
Level level;
private void Start() //sets it to tag breakable identity ** better to tell it how to destroy then not to destroy cause indestructible is defualt** // Calls the Count the blocks by adding 1 of Level Script // Method to add up all blocks
{
CountBreakableBlocks();
}
private void CountBreakableBlocks()
{
level = FindObjectOfType<Level>();
if (tag == "Breakable")
{
level.CountBlocks();
}
}
//example
//[SerializeField] Level level; Ex of Linking up way to count blockable breaks gives good control
private void OnCollisionEnter2D(Collision2D collision)
{
if (tag == "Breakable")
{
Destroy(gameObject);
}
}
private void DestroyBlock()
{
PlayBlockDestroySFX(); //(Create audio souce) play clip at point its breakSound and its going be the main camera transform position // //Calls Gamestatus Script and uses the AddToScoreFunction with the DetroyBlock funct that already has a counter from levels script to help set score
Destroy(gameObject); //small g game object means the specific game object that the script is in
level.BlockDestroyed(); //Calls The BlockDestroyed Function in Level Script that is Cached //load next scene??
TriggerSparklesVFX(); // Calls the SparklesVFX funct
}
private void PlayBlockDestroySFX()
{
FindObjectOfType<GameSession>().AddToScore();
AudioSource.PlayClipAtPoint(breakSound, Camera.main.transform.position);
}
private void TriggerSparklesVFX()
{
GameObject sparkles = Instantiate(blockSparklesVFX, transform.position, transform.rotation); // simplest bit of instantiate is just instantiate(object original) we need poistion and rotation
Destroy(sparkles, 1f); // need to make sure its not on going so must destroy the effect
}
}