using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class LightBeam : MonoBehaviour {
|
|
|
|
public Transform target;
|
|
public Transform lightBeam;
|
|
|
|
private Searchlight.SearchState searchState;
|
|
|
|
// Use this for initialization
|
|
void Start () {
|
|
NotificationServer.register("statechange Searchlight", toggleState);
|
|
NotificationServer.register("switch off", switchOff);
|
|
NotificationServer.register("restart scene", resetState);
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update () {
|
|
Vector3 lookAtPos = target.position;
|
|
lookAtPos.y = lightBeam.position.y;
|
|
lightBeam.LookAt(target);
|
|
}
|
|
|
|
private void toggleState() {
|
|
if (searchState == Searchlight.state)
|
|
return;
|
|
if (!isActiveAndEnabled)
|
|
return;
|
|
searchState = Searchlight.state;
|
|
GetComponent<Animator>().SetBool("isSeen", (Searchlight.state == Searchlight.SearchState.Chasing));
|
|
}
|
|
|
|
private void resetState() {
|
|
searchState = Searchlight.SearchState.Spline;
|
|
lightBeam.gameObject.SetActive(true);
|
|
target.gameObject.SetActive(true);
|
|
if (isActiveAndEnabled)
|
|
GetComponent<Animator>().SetBool("isSeen", false);
|
|
}
|
|
|
|
private void switchOff(object offObject) {
|
|
GameObject offGO = offObject as GameObject;
|
|
// Debug.LogWarning(offGO + " vs " + gameObject);
|
|
if (offGO == gameObject)
|
|
{
|
|
lightBeam.gameObject.SetActive(false);
|
|
target.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
}
|