using System.Collections; using System.Collections.Generic; using UnityEngine; public class LighthouseLanding : MonoBehaviour { public bool switchedOff = false; private bool isTriggering = false; private Searchlight.SearchState searchState; static private Transform lastTriggered; void Awake() { NotificationServer.register("statechange Searchlight", searchlightStateChanged); NotificationServer.register("switch off", switchBeamOff); NotificationServer.register("restart scene", restartScene); } void OnTriggerEnter(Collider other) { if (switchedOff) return; if (other.tag != "Player") return; if (Searchlight.state == Searchlight.SearchState.Chasing) return; if (isTriggering) return; isTriggering = true; NotificationServer.notify("show TakeoverButton"); lastTriggered = transform; } void OnTriggerExit(Collider other) { if (switchedOff) return; if (other.tag != "Player") return; if (!isTriggering) return; isTriggering = false; NotificationServer.notify("hide TakeoverButton"); } void searchlightStateChanged() { if (searchState == Searchlight.state) return; searchState = Searchlight.state; if (switchedOff) return; if (isTriggering && Searchlight.state == Searchlight.SearchState.Chasing) { isTriggering = false; NotificationServer.notify("hide TakeoverButton"); } } public void switchOff() { NotificationServer.notify("hide TakeoverButton"); NotificationServer.notify("play sfx", "assassination:0.75"); NotificationServer.notify("switch off", lastTriggered.parent.gameObject); } public void switchBeamOff(object _) { if (transform == lastTriggered) switchedOff = true; } public void restartScene() { switchedOff = false; } }