Advertisement
Guest User

Untitled

a guest
Sep 13th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class BrickScript : MonoBehaviour {
  6.  
  7.  
  8. public int TimesHit;
  9. private int MaxHit;
  10.  
  11. public Sprite[] brickhit;
  12. public static int brickCount = 0;
  13.  
  14. private LevelManagerScript LM;
  15. private bool isBreakable;
  16.  
  17. void Start ()
  18. {
  19. isBreakable = (this.tag == "Breakable");
  20. if (isBreakable)
  21. {
  22. brickCount++;
  23. }
  24.  
  25. LM = GameObject.FindObjectOfType<LevelManagerScript>();
  26. print("Bricks: "+ brickCount);
  27. }
  28.  
  29. void OnCollisionEnter2D (Collision2D collision)
  30. {
  31. bool Breakable = (this.tag == "Breakable");
  32. if (Breakable)
  33. {
  34. HandleHit ();
  35. }
  36. }
  37.  
  38. void HandleHit ()
  39. {
  40. TimesHit += 1;
  41. MaxHit = brickhit.Length + 1;
  42.  
  43. if (TimesHit >= MaxHit)
  44. {
  45. brickCount--;
  46. print("Bricks: " + brickCount);
  47. Destroy (gameObject);
  48. print ("Brick Destroyed");
  49. //SimulateWin();
  50. }
  51.  
  52. else if(TimesHit <= MaxHit)
  53. {
  54. LoadSprite();
  55. }
  56.  
  57. }
  58.  
  59.  
  60. void LoadSprite ()
  61. {
  62. int spriteIndex = TimesHit - 1;
  63. //if(brickhit[spriteIndex])
  64. this.GetComponent<SpriteRenderer>().sprite = brickhit[spriteIndex];
  65. }
  66.  
  67. void SimulateWin ()
  68. {
  69. LM.LoadNextLevel();
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement