View difference between Paste ID: vhqj0a9x and YFcdA1JV
SHOW: | | - or go back to the newest paste.
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
}