Advertisement
Guest User

Untitled

a guest
Dec 6th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.26 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.UI;
  4.  
  5. public class bl_DeathZone : bl_PhotonHelper {
  6. /// <summary>
  7. /// Time maximum that may be prohibited in the area before dying
  8. /// </summary>
  9. public int TimeToDeat = 5;
  10. /// <summary>
  11. /// message that will appear in the UI when this within the zone
  12. /// </summary>
  13. public string CustomMessage = "";
  14. private bool mOn = false;
  15. public GameObject KillZoneUI = null;
  16.  
  17. /// <summary>
  18. ///
  19. /// </summary>
  20. protected override void Awake()
  21. {
  22. base.Awake();
  23. if (this.transform.GetComponent<Collider>() != null)
  24. {
  25. transform.GetComponent<Collider>().isTrigger = true;
  26. }
  27. else
  28. {
  29. Debug.LogError("This Go " + gameObject.name + " need have a collider");
  30. Destroy(this);
  31. }
  32. if (KillZoneUI == null)
  33. {
  34. KillZoneUI = bl_GameManager.KillZone;
  35. }
  36. }
  37. /// <summary>
  38. ///
  39. /// </summary>
  40. /// <param name="mCol"></param>
  41. void OnTriggerEnter(Collider mCol)
  42. {
  43. if (mCol.transform.tag == bl_PlayerSettings.LocalTag)//when is player local enter
  44. {
  45. bl_PlayerDamageManager pdm = mCol.transform.root.GetComponent<bl_PlayerDamageManager>();// get the component damage
  46.  
  47. if (pdm != null && pdm.health > 0 && !mOn)
  48. {
  49. InvokeRepeating("regressive", 1, 1);
  50. if (KillZoneUI != null)
  51. {
  52. KillZoneUI.SetActive(true);
  53. Text mText = KillZoneUI.GetComponentInChildren<Text>();
  54. mText.text = CustomMessage + "<color=red><size=25>" + TimeToDeat.ToString("00") + "</size>s</color>";
  55. }
  56. mOn = true;
  57. }
  58.  
  59. }
  60. }
  61. /// <summary>
  62. ///
  63. /// </summary>
  64. /// <param name="mCol"></param>
  65. void OnTriggerExit(Collider mCol)
  66. {
  67. if (mCol.transform.tag == bl_PlayerSettings.LocalTag)// if player exit of zone then cancel countdown
  68. {
  69. CancelInvoke("regressive");
  70. TimeToDeat = 5; // restart time
  71. if (KillZoneUI != null)
  72. {
  73. KillZoneUI.SetActive(false);
  74. }
  75. mOn = false;
  76. }
  77. }
  78. /// <summary>
  79. /// Start CountDown when player is on Trigger
  80. /// </summary>
  81. void regressive()
  82. {
  83. TimeToDeat--;
  84. if (KillZoneUI != null)
  85. {
  86. Text mText = KillZoneUI.GetComponentInChildren<Text>();
  87. mText.text = CustomMessage + "<color=red><size=25>"+TimeToDeat.ToString("00")+"</size>s</color>";
  88. }
  89. if (TimeToDeat <= 0)
  90. {
  91. FindPlayerRoot(bl_GameManager.m_view).GetComponent<bl_PlayerDamageManager>().Suicide();
  92. CancelInvoke("regressive");
  93. TimeToDeat = 5;
  94. if (KillZoneUI != null)
  95. {
  96. KillZoneUI.SetActive(false);
  97. }
  98. mOn = false;
  99. }
  100. }
  101. /// <summary>
  102. ///
  103. /// </summary>
  104. void OnDrawGizmos()
  105. {
  106. Gizmos.DrawIcon(transform.position, "DeathZone.psd", true);
  107. }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement