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.

67 lines
1.7 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. // originalPos = text.rectTransform.anchoredPosition3D;
  18. }
  19. public void spottedBoat()
  20. {
  21. LeanTween.cancel(text.gameObject, false);
  22. LeanTween.cancel(slider.gameObject, false);
  23. // lastSpotted = Time.timeSinceLevelLoad;
  24. NotificationServer.notify("show AlertText");
  25. text.text = "hide!";
  26. setTimer(0f);
  27. }
  28. public void lostBoat()
  29. {
  30. LeanTween.cancel(text.gameObject, false);
  31. LeanTween.cancel(slider.gameObject, false);
  32. NotificationServer.notify("show AlertText");
  33. NotificationServer.notify("show AlertTimer");
  34. text.text = "stay hidden";
  35. LeanTween.value(slider.gameObject, 0f, 1f, hideTime).setOnUpdate((float val)=>{
  36. setTimer(val);
  37. }).setOnComplete(()=>{
  38. NotificationServer.notify("hide AlertTimer");
  39. NotificationServer.notify("statechange Searchlight returning");
  40. NotificationServer.notify("statechange Searchlight");
  41. text.text = "hidden...";
  42. LeanTween.delayedCall(text.gameObject, 2f, ()=>{
  43. NotificationServer.notify("hide AlertText");
  44. });
  45. });
  46. }
  47. public void restartScene()
  48. {
  49. LeanTween.cancel(text.gameObject, false);
  50. LeanTween.cancel(slider.gameObject, false);
  51. NotificationServer.notify("hide AlertText");
  52. NotificationServer.notify("hide AlertTimer");
  53. }
  54. public void setTimer(float val)
  55. {
  56. slider.value = val;
  57. }
  58. }