Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class BrickScript : MonoBehaviour {
- public int TimesHit;
- private int MaxHit;
- public Sprite[] brickhit;
- public static int brickCount = 0;
- private LevelManagerScript LM;
- private bool isBreakable;
- void Start ()
- {
- isBreakable = (this.tag == "Breakable");
- if (isBreakable)
- {
- brickCount++;
- }
- LM = GameObject.FindObjectOfType<LevelManagerScript>();
- print("Bricks: "+ brickCount);
- }
- void OnCollisionEnter2D (Collision2D collision)
- {
- bool Breakable = (this.tag == "Breakable");
- if (Breakable)
- {
- HandleHit ();
- }
- }
- void HandleHit ()
- {
- TimesHit += 1;
- MaxHit = brickhit.Length + 1;
- if (TimesHit >= MaxHit)
- {
- brickCount--;
- print("Bricks: " + brickCount);
- Destroy (gameObject);
- print ("Brick Destroyed");
- //SimulateWin();
- }
- else if(TimesHit <= MaxHit)
- {
- LoadSprite();
- }
- }
- void LoadSprite ()
- {
- int spriteIndex = TimesHit - 1;
- //if(brickhit[spriteIndex])
- this.GetComponent<SpriteRenderer>().sprite = brickhit[spriteIndex];
- }
- void SimulateWin ()
- {
- LM.LoadNextLevel();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement