RtkTrigger.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class RtkTrigger : MonoBehaviour
  5. {
  6. public List<GameObject> list_Obj;
  7. public List<GameObject> list_Box;
  8. public List<GameObject> list_Point;
  9. public bool finish;
  10. private void Start()
  11. {
  12. // finish = false;
  13. }
  14. private void Update()
  15. {
  16. if (API_SVR.GetHead() != null)
  17. if (transform.position != API_SVR.GetHead().position)
  18. {
  19. transform.position = API_SVR.GetHead().position;
  20. }
  21. }
  22. private void OnTriggerEnter(Collider other)
  23. {
  24. QueryBox(other, true);
  25. }
  26. private void OnTriggerExit(Collider other)
  27. {
  28. QueryBox(other, false);
  29. }
  30. /// <summary>
  31. /// 查找触发器
  32. /// </summary>
  33. /// <param name="other"></param>
  34. /// <param name="state"></param>
  35. private void QueryBox(Collider other, bool state)
  36. {
  37. Debug.Log(other.name);
  38. for (int i = 0; i < list_Box.Count; i++)
  39. {
  40. if (other.name == list_Box[i].name)
  41. {
  42. SetShowObject(list_Point[i], list_Obj[i], state);
  43. break;
  44. }
  45. }
  46. }
  47. /// <summary>
  48. /// 设置显示效果(触发器判定选择)
  49. /// </summary>
  50. private void SetShowObject(GameObject Obj, GameObject Effect, bool state)
  51. {
  52. finish = state;
  53. Effect.SetActive(state);
  54. Obj.SetActive(!state);
  55. }
  56. }