Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class Building : MonoBehaviour
  7. {
  8.  
  9. public List<Column> columns;
  10.  
  11. public Sprite shortcircuit;
  12. public Sprite notShortcircuit;
  13.  
  14. private bool shortCircuit;
  15. // Start is called before the first frame update
  16. void Start()
  17. {
  18. shortCircuit = false;
  19. }
  20.  
  21. // Update is called once per frame
  22. void Update()
  23. {
  24. if (ifAllOn()) {
  25. shortCircuit = true;
  26. this.gameObject.GetComponent<SpriteRenderer>().sprite = shortcircuit;
  27. } else {
  28. shortCircuit = false;
  29. this.gameObject.GetComponent<SpriteRenderer>().sprite = notShortcircuit;
  30. }
  31. }
  32.  
  33. void OnTriggerStay2D(Collider2D collision) {
  34. if(collision.tag == "Player"){
  35. CharacterController character = collision.gameObject.GetComponent<CharacterController>();
  36.  
  37. if (character != null && shortCircuit) {
  38. if (character.GetComponent<BootsBar>().getBootsHealth() > 0) {
  39. // if player's boots' health is above 0, the boots will take damage instead of the player when standing on a short-circuited building
  40. if (!character.GetComponent<BootsBar>().isOnCD()) {
  41. character.GetComponent<BootsBar>().putOnCD();
  42. character.GetComponent<BootsBar>().loseBootsHealth();
  43. Debug.Log("boots health: " + character.GetComponent<BootsBar>().getBootsHealth());
  44. }
  45.  
  46. } else {
  47. character.LoseHealth();
  48. Debug.Log(character.health);
  49. }
  50. }
  51. }
  52. }
  53.  
  54. // turn all the building lights on due to wrong switch by player
  55. public void turnAllOn()
  56. {
  57. foreach (Column column in columns)
  58. {
  59. if (!column.ifWindowOn()) {
  60. column.turnOnWindows(false);
  61. }
  62. }
  63. }
  64.  
  65. public bool ifAllOn() {
  66. foreach (Column column in columns) {
  67. if (!column.ifWindowOn()) {
  68. return false;
  69. }
  70. }
  71. return true;
  72. }
  73.  
  74. public List<Column> getColumns() {
  75. return columns;
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement