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.

65 lines
1.6 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class AlertController : MonoBehaviour
  6. {
  7. public Text text;
  8. public Slider slider;
  9. public float hideTime = 5f;
  10. // private Vector3 originalPos;
  11. // private float lastSpotted;
  12. void Start ()
  13. {
  14. NotificationServer.register("spotted boat", spottedBoat);
  15. NotificationServer.register("lost boat", lostBoat);
  16. NotificationServer.register("restart scene", restartScene);
  17. }
  18. public void spottedBoat()
  19. {
  20. LeanTween.cancel(text.gameObject, false);
  21. LeanTween.cancel(slider.gameObject, false);
  22. NotificationServer.notify("show AlertText");
  23. text.text = "hide!";
  24. setTimer(0f);
  25. }
  26. public void lostBoat()
  27. {
  28. LeanTween.cancel(text.gameObject, false);
  29. LeanTween.cancel(slider.gameObject, false);
  30. NotificationServer.notify("show AlertText");
  31. NotificationServer.notify("show AlertTimer");
  32. text.text = "stay hidden";
  33. LeanTween.value(slider.gameObject, 0f, 1f, hideTime).setOnUpdate((float val)=>{
  34. setTimer(val);
  35. }).setOnComplete(()=>{
  36. NotificationServer.notify("hide AlertTimer");
  37. NotificationServer.notify("statechange Searchlight returning");
  38. NotificationServer.notify("statechange Searchlight");
  39. text.text = "hidden...";
  40. LeanTween.delayedCall(text.gameObject, 2f, ()=>{
  41. NotificationServer.notify("hide AlertText");
  42. });
  43. });
  44. }
  45. public void restartScene()
  46. {
  47. LeanTween.cancel(text.gameObject, false);
  48. LeanTween.cancel(slider.gameObject, false);
  49. NotificationServer.notify("hide AlertText");
  50. NotificationServer.notify("hide AlertTimer");
  51. }
  52. public void setTimer(float val)
  53. {
  54. slider.value = val;
  55. }
  56. }