SceneEventBombLogic.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityGameFramework.Runtime;
  6. /// <summary>
  7. /// 场景组件 炸弹
  8. /// </summary>
  9. public class SceneEventBombLogic : MonoBehaviour
  10. {
  11. public string skillId = "6010012";
  12. public float countdown = 3;
  13. private bool isCountDown = false;
  14. private bool isLive = true;
  15. private void Awake()
  16. {
  17. SceneCmptManager.Instance.AddMechanism(this.gameObject);
  18. }
  19. // Start is called before the first frame update
  20. void Start()
  21. {
  22. SceneEventBomb info = this.gameObject.GetComponent<SceneEventBomb>();
  23. this.skillId = info.skillId;
  24. this.countdown = info.countdown;
  25. }
  26. public void Update()
  27. {
  28. if(!isLive)
  29. {
  30. return;
  31. }
  32. if(isCountDown)
  33. {
  34. countdown -= Time.deltaTime;
  35. if(countdown <= 0)
  36. {
  37. Bomb();
  38. }
  39. }
  40. }
  41. public void OnTriggerEnter(Collider collider)
  42. {
  43. Role r = collider.GetComponent<Role>();
  44. if(r && !isCountDown)
  45. {
  46. Animator anim = this.GetComponent<Animator>();
  47. anim.Play("warning", 0, 0);
  48. isCountDown = true;
  49. SceneCmptManager.Instance.OpenMechanism(this.gameObject);
  50. }
  51. }
  52. public void Bomb()
  53. {
  54. isLive = false;
  55. Animator anim = this.GetComponent<Animator>();
  56. anim.Play("destroy");
  57. SceneEventBombEntryLogic bombEntry = this.transform.Find("zha dan").GetComponent<SceneEventBombEntryLogic>();
  58. List<Role> roleList = bombEntry.GetEntryRoleList();
  59. foreach(var item in roleList)
  60. {
  61. if (!item || item.isDie)
  62. {
  63. continue;
  64. }
  65. X2Battle.X2BattleManager.Instance.mBulletModel.OnCastSkill(
  66. 0, skillId,
  67. false, X2Battle.EBulletCastPoint.ECAST_POINT_DEFLUAT, item.mData.UID, false);
  68. }
  69. }
  70. public void EnableCollider()
  71. {
  72. }
  73. public void OnClickInteractive()
  74. {
  75. }
  76. }