You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.5 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class LighthouseLanding : MonoBehaviour
  5. {
  6. public bool switchedOff = false;
  7. private bool isTriggering = false;
  8. static private Transform lastTriggered;
  9. void Awake()
  10. {
  11. NotificationServer.register("statechange Searchlight", searchlightStateChanged);
  12. NotificationServer.register("switch off", switchBeamOff);
  13. }
  14. void OnTriggerEnter(Collider other)
  15. {
  16. if (switchedOff)
  17. return;
  18. if (other.tag != "Player")
  19. return;
  20. if (Searchlight.state == Searchlight.SearchState.Chasing)
  21. return;
  22. if (isTriggering)
  23. return;
  24. isTriggering = true;
  25. NotificationServer.notify("show TakeoverButton");
  26. lastTriggered = transform;
  27. }
  28. void OnTriggerExit(Collider other)
  29. {
  30. if (switchedOff)
  31. return;
  32. if (other.tag != "Player")
  33. return;
  34. if (!isTriggering)
  35. return;
  36. isTriggering = false;
  37. NotificationServer.notify("hide TakeoverButton");
  38. }
  39. void searchlightStateChanged()
  40. {
  41. if (switchedOff)
  42. return;
  43. if (isTriggering && Searchlight.state == Searchlight.SearchState.Chasing)
  44. {
  45. isTriggering = false;
  46. NotificationServer.notify("hide TakeoverButton");
  47. }
  48. }
  49. public void switchOff()
  50. {
  51. NotificationServer.notify("hide TakeoverButton");
  52. NotificationServer.notify("play sfx", "assassination:0.75");
  53. NotificationServer.notify("switch off", lastTriggered.parent.gameObject);
  54. }
  55. public void switchBeamOff(object _)
  56. {
  57. if (transform == lastTriggered)
  58. switchedOff = true;
  59. }
  60. }