JustPaste.it

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BrickShot : MonoBehaviour {

    public Sprite[] hitSprites;
    public static int BlockNumber=0;

    private bool isBreakable;
    public int maxHits;
    public int timesHit=0;
    private LevelManager levelmanager;


    // Use this for initialization
    void Start ()
    {
        maxHits = hitSprites.Length + 1;

        isBreakable = (this.tag == "Breakable");
        if (isBreakable) {
            BlockNumber++;
        }
        levelmanager=GameObject.FindObjectOfType<LevelManager>()

    }
    
    // Update is called once per frame
    void Update ()
    {
        

        print ("Remaining Blocks " + BlockNumber);

        
    }
    void OnCollisionEnter2D (Collision2D BallBrick)
    {
        timesHit++;
        if (isBreakable == true) {
            TackleCollision();
        }

    }
    void TackleCollision ()
    {
        if (timesHit >= maxHits) {
            Destroy (gameObject);
            BlockNumber--;

        } else {
            this.GetComponent<SpriteRenderer>().sprite = hitSprites[timesHit-1];

        }


    }
}