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.

82 lines
1.7 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. private Searchlight.SearchState searchState;
  9. static private Transform lastTriggered;
  10. void Awake()
  11. {
  12. NotificationServer.register("statechange Searchlight", searchlightStateChanged);
  13. NotificationServer.register("switch off", switchBeamOff);
  14. NotificationServer.register("restart scene", restartScene);
  15. }
  16. void OnTriggerEnter(Collider other)
  17. {
  18. if (switchedOff)
  19. return;
  20. if (other.tag != "Player")
  21. return;
  22. if (Searchlight.state == Searchlight.SearchState.Chasing)
  23. return;
  24. if (isTriggering)
  25. return;
  26. isTriggering = true;
  27. NotificationServer.notify("show TakeoverButton");
  28. lastTriggered = transform;
  29. }
  30. void OnTriggerExit(Collider other)
  31. {
  32. if (switchedOff)
  33. return;
  34. if (other.tag != "Player")
  35. return;
  36. if (!isTriggering)
  37. return;
  38. isTriggering = false;
  39. NotificationServer.notify("hide TakeoverButton");
  40. }
  41. void searchlightStateChanged()
  42. {
  43. if (searchState == Searchlight.state)
  44. return;
  45. searchState = Searchlight.state;
  46. if (switchedOff)
  47. return;
  48. if (isTriggering && Searchlight.state == Searchlight.SearchState.Chasing)
  49. {
  50. isTriggering = false;
  51. NotificationServer.notify("hide TakeoverButton");
  52. }
  53. }
  54. public void switchOff()
  55. {
  56. NotificationServer.notify("hide TakeoverButton");
  57. NotificationServer.notify("play sfx", "assassination:0.75");
  58. NotificationServer.notify("switch off", lastTriggered.parent.gameObject);
  59. }
  60. public void switchBeamOff(object _)
  61. {
  62. if (transform == lastTriggered)
  63. switchedOff = true;
  64. }
  65. public void restartScene()
  66. {
  67. switchedOff = false;
  68. }
  69. }