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.

48 lines
1.3 KiB

7 years ago
7 years ago
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class LightBeam : MonoBehaviour {
  5. public Transform target;
  6. public Transform lightBeam;
  7. private Searchlight.SearchState searchState;
  8. // Use this for initialization
  9. void Start () {
  10. NotificationServer.register("statechange Searchlight", toggleState);
  11. NotificationServer.register("switch off", switchOff);
  12. NotificationServer.register("restart scene", resetState);
  13. }
  14. // Update is called once per frame
  15. void Update () {
  16. Vector3 lookAtPos = target.position;
  17. lookAtPos.y = lightBeam.position.y;
  18. lightBeam.LookAt(target);
  19. }
  20. private void toggleState() {
  21. if (searchState == Searchlight.state)
  22. return;
  23. searchState = Searchlight.state;
  24. GetComponent<Animator>().SetBool("isSeen", (Searchlight.state == Searchlight.SearchState.Chasing));
  25. }
  26. private void resetState() {
  27. lightBeam.gameObject.SetActive(true);
  28. target.gameObject.SetActive(true);
  29. GetComponent<Animator>().SetBool("isSeen", false);
  30. }
  31. private void switchOff(object offObject) {
  32. GameObject offGO = offObject as GameObject;
  33. // Debug.LogWarning(offGO + " vs " + gameObject);
  34. if (offGO == gameObject)
  35. {
  36. lightBeam.gameObject.SetActive(false);
  37. target.gameObject.SetActive(false);
  38. }
  39. }
  40. }