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.

35 lines
843 B

  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. }
  12. // Update is called once per frame
  13. void Update () {
  14. Vector3 lookAtPos = target.position;
  15. lookAtPos.y = lightBeam.position.y;
  16. lightBeam.LookAt(target);
  17. }
  18. private void toggleState() {
  19. GetComponent<Animator>().SetBool("isSeen", (Searchlight.state == Searchlight.SearchState.Chasing));
  20. }
  21. private void switchOff() {
  22. lightBeam.gameObject.SetActive(false);
  23. target.gameObject.SetActive(false);
  24. }
  25. }