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.

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