coding_giants

L15 - BricksScript

Mar 26th, 2024
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class BricksScript : MonoBehaviour
  6. {
  7.     //Amount of life of the brick
  8.    
  9.     public int life = 1;
  10.  
  11.     //Each time the brick collides with anything
  12.     private void OnCollisionEnter(Collision collision)
  13.     {
  14.         //If it has "Ball" tag
  15.         if(collision.gameObject.tag == "Ball")
  16.         {
  17.             //decreasing life
  18.             life--;
  19.             //if life is lower or equal 0
  20.             if(life <= 0)
  21.             {
  22.                 GameManager.instance.bricks.Remove(this.gameObject);
  23.                 Destroy(gameObject); //Destroy the object
  24.             }
  25.         }
  26.     }
  27. }
Add Comment
Please, Sign In to add comment