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.

49 lines
1.4 KiB

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