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.

52 lines
1.4 KiB

7 years ago
7 years ago
7 years ago
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. if (!isActiveAndEnabled)
  24. return;
  25. searchState = Searchlight.state;
  26. GetComponent<Animator>().SetBool("isSeen", (Searchlight.state == Searchlight.SearchState.Chasing));
  27. }
  28. private void resetState() {
  29. searchState = Searchlight.SearchState.Spline;
  30. lightBeam.gameObject.SetActive(true);
  31. target.gameObject.SetActive(true);
  32. if (isActiveAndEnabled)
  33. GetComponent<Animator>().SetBool("isSeen", false);
  34. }
  35. private void switchOff(object offObject) {
  36. GameObject offGO = offObject as GameObject;
  37. // Debug.LogWarning(offGO + " vs " + gameObject);
  38. if (offGO == gameObject)
  39. {
  40. lightBeam.gameObject.SetActive(false);
  41. target.gameObject.SetActive(false);
  42. }
  43. }
  44. }