ChuanSongMen.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using System;
  5. using UnityEngine.EventSystems;
  6. public class ChuanSongMen : MonoBehaviour
  7. {
  8. /// <summary>
  9. /// 门的类型
  10. /// </summary>
  11. public int doorType = 1;
  12. /// <summary>
  13. /// 出生时间
  14. /// </summary>
  15. public float liveTime = 2.0f;
  16. /// <summary>
  17. /// 点击回调
  18. /// </summary>
  19. public Action<int> clickAC = null;
  20. /// <summary>
  21. /// 进入碰撞器回调
  22. /// </summary>
  23. public Action<int, GameObject> enterAC = null;
  24. private bool bEnable = false;
  25. private void OnEnable()
  26. {
  27. Invoke("LateEnable", liveTime);
  28. }
  29. private void LateEnable()
  30. {
  31. bEnable = true;
  32. }
  33. private void OnMouseUpAsButton()
  34. {
  35. Debug.Log("点击触发器");
  36. if (bEnable == false)
  37. {
  38. return;
  39. }
  40. if (clickAC != null)
  41. {
  42. clickAC(doorType);
  43. }
  44. }
  45. private void OnTriggerEnter(Collider other)
  46. {
  47. Debug.Log("进入到触发器 " + other.name);
  48. if (bEnable == false)
  49. {
  50. return;
  51. }
  52. if (enterAC != null)
  53. {
  54. enterAC(doorType, other.gameObject);
  55. }
  56. }
  57. }