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.

38 lines
1.0 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() {
  28. lightBeam.gameObject.SetActive(false);
  29. target.gameObject.SetActive(false);
  30. }
  31. }