Advertisement
johnnygoodguy2000

DestroyBlockOnContact.cs

May 12th, 2024
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.76 KB | Gaming | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class DestroyBlockOnContact : MonoBehaviour
  6. {
  7.     // Start is called before the first frame update
  8.     void Start()
  9.     {
  10.        
  11.     }
  12.  
  13.     // Update is called once per frame
  14.     void Update()
  15.     {
  16.        
  17.     }
  18.  
  19.     // This method is called when the attached collider enters another collider
  20.     void OnTriggerEnter2D(Collider2D other)
  21.     {
  22.         Debug.Log("OnTriggerEnter2D called"); // Add this line to check if OnTriggerEnter2D is being called
  23.  
  24.         if (other.tag == "BreakableGround") // Check if the colliding object is tagged as "BreakableGround"
  25.         {  
  26.             Destroy(other.gameObject);// Destroy the game object
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement