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.

66 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. text.text = "hidden...";
  41. LeanTween.delayedCall(text.gameObject, 2f, ()=>{
  42. NotificationServer.notify("hide AlertText");
  43. });
  44. });
  45. }
  46. public void restartScene()
  47. {
  48. LeanTween.cancel(text.gameObject, false);
  49. LeanTween.cancel(slider.gameObject, false);
  50. NotificationServer.notify("hide AlertText");
  51. NotificationServer.notify("hide AlertTimer");
  52. }
  53. public void setTimer(float val)
  54. {
  55. slider.value = val;
  56. }
  57. }