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.

43 lines
1.2 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. // Use this for initialization
  8. void Start () {
  9. NotificationServer.register("statechange Searchlight", toggleState);
  10. NotificationServer.register("switch off", switchOff);
  11. NotificationServer.register("restart scene", resetState);
  12. }
  13. // Update is called once per frame
  14. void Update () {
  15. Vector3 lookAtPos = target.position;
  16. lookAtPos.y = lightBeam.position.y;
  17. lightBeam.LookAt(target);
  18. }
  19. private void toggleState() {
  20. GetComponent<Animator>().SetBool("isSeen", (Searchlight.state == Searchlight.SearchState.Chasing));
  21. }
  22. private void resetState() {
  23. lightBeam.gameObject.SetActive(true);
  24. target.gameObject.SetActive(true);
  25. GetComponent<Animator>().SetBool("isSeen", false);
  26. }
  27. private void switchOff(object offObject) {
  28. GameObject offGO = offObject as GameObject;
  29. // Debug.LogWarning(offGO + " vs " + gameObject);
  30. if (offGO == gameObject)
  31. {
  32. lightBeam.gameObject.SetActive(false);
  33. target.gameObject.SetActive(false);
  34. }
  35. }
  36. }