TimerAd.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System.Collections.Generic;
  2. using JsonFx.Json;
  3. using UnityEngine;
  4. using System.Collections;
  5. public class TimerAd : MonoBehaviour
  6. {
  7. public int StartTimer = 8;
  8. public float Timer = 8;
  9. public UILabel timer;
  10. public UILabel text;
  11. public UILabel textFact;
  12. private NGUIMenuScript hNGUIMenuScript;
  13. private UIElementTransition elementTransition;
  14. private SoundManagerCS hSoundManagerCS;
  15. private InGameScriptCS hInGameScriptCS;
  16. void Start ()
  17. {
  18. hNGUIMenuScript = (NGUIMenuScript)GameObject.Find("UI Root (2D)").GetComponent(typeof(NGUIMenuScript));
  19. hSoundManagerCS = (SoundManagerCS)GameObject.Find("SoundManager").GetComponent(typeof(SoundManagerCS));
  20. hInGameScriptCS = (InGameScriptCS)GameObject.Find("Player").GetComponent(typeof(InGameScriptCS));
  21. elementTransition = GetComponent<UIElementTransition>();
  22. timer.text = "";
  23. }
  24. void OnEnable()
  25. {
  26. if (elementTransition==null)
  27. {
  28. elementTransition = GetComponent<UIElementTransition>();
  29. }
  30. elementTransition.Show();
  31. Timer = StartTimer;
  32. }
  33. void Update ()
  34. {
  35. Timer = Timer - Time.deltaTime;
  36. if(Timer <= 0)
  37. {
  38. Timer = 0;
  39. StartCoroutine(SetActiveElement());
  40. if (AdManager.Instance.SmokeCam != null)
  41. {
  42. AdManager.Instance.SmokeCam.enabled = (true);
  43. }
  44. }
  45. timer.text = ((int)Timer).ToString();
  46. //text.text = string.Format(Localization.instance.Get("ad.label.text"), LevelsManager.Instance.CurrentLevelIndex + 1);
  47. }
  48. private IEnumerator SetActiveElement()
  49. {
  50. yield return new WaitForSeconds(0);
  51. //hSoundManagerCS.toggleSoundEnabled(true);
  52. //hSoundManagerCS.toggleMusicEnabled(true);
  53. hNGUIMenuScript.CloseMenu(NGUIMenuScript.NGUIMenus.Banner);
  54. if (!InstructionButtonHandler.FirstPlay)
  55. {
  56. NGUIMenuScript.Instance.CurStatePopup = NGUIMenuScript.StatesMenuForPopup.None;
  57. hInGameScriptCS.launchGame();
  58. }
  59. else
  60. {
  61. NGUIMenuScript.Instance.CurStatePopup = NGUIMenuScript.StatesMenuForPopup.None;
  62. hInGameScriptCS.launchGame();
  63. }
  64. NGUIMenuScript.Instance.ShowMenu(NGUIMenuScript.NGUIMenus.RaceStart);
  65. }
  66. }