InGameScriptCS.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. /*
  2. * FUNCITON:
  3. * - This script holds the global variables that the other scripts are dependent on.
  4. * - It provides interaction among scripts.
  5. * - This script controls game states (launch, pause, death etc.)
  6. *
  7. * USED BY: This script is a part of the "Player" prefab.
  8. *
  9. */
  10. using UnityEngine;
  11. using System.Collections;
  12. using System;
  13. using UnityEngine.SceneManagement;
  14. public class InGameScriptCS : MonoBehaviour {
  15. public static InGameScriptCS Instance { get; private set; }
  16. public bool Resurected;
  17. private int CurrentEnergy = 100; //player's energy (set to zero on death)
  18. private int iLevelScore = 0; //current score (calculated based on distance traveled)
  19. private int iCurrencyCount = 9000;//
  20. private bool customMenuEnabled = false;
  21. public UILabel DistanceGameOver;
  22. public UILabel GiftsGameOver;
  23. public UILabel PointsGameOver;
  24. //script references
  25. private MenuScriptCS hMenuScriptCS;
  26. private NGUIMenuScript hNGUIMenuScript;
  27. private ControllerScriptCS hControllerScriptCS;
  28. private SoundManagerCS hSoundManagerCS;
  29. private PowerupsMainControllerCS hPowerupsMainControllerCS;
  30. private EnemyControllerCS hEnemyControllerCS;
  31. private CameraControllerCS hCameraControllerCS;
  32. private MissionsControllerCS hMissionsControllerCS;
  33. private GlobalAchievementControllerCS hGlobalAchievementControllerCS;
  34. private int iPauseStatus = 0;
  35. public int iDeathStatus = 0;
  36. private int iMenuStatus;
  37. private bool bGameOver = false;
  38. public bool bGamePaused = false;
  39. // Use this for initialization
  40. void Start ()
  41. {
  42. Instance = this;
  43. PlayerPrefs.SetInt("AdCounter", 0);
  44. PlayerPrefs.Save();
  45. //PlayerPrefs.DeleteAll(); //DEBUG
  46. Application.targetFrameRate = 60; //ceiling the frame rate on 60 (debug only)
  47. RenderSettings.fog = true; //turn on fog on launch
  48. if (GameObject.Find("MenuGroup"))//check while type of menu is active (custom or ngui)
  49. {
  50. customMenuEnabled = true;
  51. hMenuScriptCS = (MenuScriptCS)GameObject.Find("MenuGroup").GetComponent(typeof(MenuScriptCS));
  52. }
  53. else
  54. hNGUIMenuScript = (NGUIMenuScript)GameObject.Find("UI Root (2D)").GetComponent(typeof(NGUIMenuScript));
  55. hSoundManagerCS = (SoundManagerCS)GameObject.Find("SoundManager").GetComponent(typeof(SoundManagerCS));
  56. hControllerScriptCS = (ControllerScriptCS)this.GetComponent(typeof(ControllerScriptCS));
  57. hPowerupsMainControllerCS = (PowerupsMainControllerCS)this.GetComponent(typeof(PowerupsMainControllerCS));
  58. hCameraControllerCS = (CameraControllerCS)GameObject.Find("Main Camera").GetComponent(typeof(CameraControllerCS));
  59. hEnemyControllerCS = (EnemyControllerCS)this.GetComponent(typeof(EnemyControllerCS));
  60. hMissionsControllerCS = (MissionsControllerCS)this.GetComponent(typeof(MissionsControllerCS));
  61. hGlobalAchievementControllerCS = (GlobalAchievementControllerCS)this.GetComponent(typeof(GlobalAchievementControllerCS));
  62. hPlayerSidesColliderScriptCS = (PlayerSidesColliderScriptCS)GameObject.Find("PlayerSidesCollider").GetComponent(typeof(PlayerSidesColliderScriptCS));
  63. hPlayerFrontColliderScriptCS = (PlayerFrontColliderScriptCS)GameObject.Find("PlayerFrontCollider").GetComponent(typeof(PlayerFrontColliderScriptCS));
  64. CurrentEnergy = 100;
  65. iPauseStatus = 0;
  66. iDeathStatus = 0;
  67. iMenuStatus = 1;
  68. bGameOver = false;
  69. bGamePaused = true;
  70. }
  71. public void SendEvent(int point)
  72. {
  73. switch (InGameScriptCS.Instance.Level)
  74. {
  75. case 1:
  76. KHD.FlurryAnalyticsTest.Instance.GameFinishLevel1(point);
  77. break;
  78. case 2:
  79. KHD.FlurryAnalyticsTest.Instance.GameFinishLevel2(point);
  80. break;
  81. case 3:
  82. KHD.FlurryAnalyticsTest.Instance.GameFinishLevel3(point);
  83. break;
  84. }
  85. }
  86. public bool isRace()
  87. {
  88. return iMenuStatus == 0;
  89. }
  90. private PlayerSidesColliderScriptCS hPlayerSidesColliderScriptCS;
  91. private PlayerFrontColliderScriptCS hPlayerFrontColliderScriptCS;
  92. public UILabel LabelCompany;
  93. void Update()
  94. {
  95. //if (NGUIMenuScript.Instance.CurStatePopup == NGUIMenuScript.StatesMenuForPopup.None)
  96. //{
  97. // //LabelCompany.gameObject.SetActive(false);
  98. //}
  99. //else
  100. //{
  101. // //LabelCompany.gameObject.SetActive(true);
  102. //}
  103. if (iMenuStatus == 0) //normal gameplay
  104. {
  105. /*if(startTimer)
  106. {
  107. Debug.Log("StartTimer");
  108. }*/
  109. }
  110. else if (iMenuStatus == 1) //display main menu and pause game
  111. {
  112. if (isCustomMenuEnabled())
  113. hMenuScriptCS.setMenuScriptStatus(true);
  114. else
  115. hNGUIMenuScript.NGUIMenuScriptEnabled(true);
  116. bGamePaused = true;
  117. iMenuStatus = 2;
  118. }
  119. //Pause GamePlay
  120. if(iPauseStatus == 1)//pause game
  121. {
  122. if (isCustomMenuEnabled())
  123. {
  124. hMenuScriptCS.setMenuScriptStatus(true);
  125. hMenuScriptCS.displayPauseMenu();
  126. }
  127. else
  128. {
  129. hNGUIMenuScript.NGUIMenuScriptEnabled(true);
  130. hNGUIMenuScript.ShowMenu(NGUIMenuScript.NGUIMenus.PauseMenu);
  131. }
  132. iPauseStatus = 2;
  133. }
  134. else if(iPauseStatus==3)//resume game
  135. {
  136. if (isCustomMenuEnabled())
  137. hMenuScriptCS.setMenuScriptStatus(false);
  138. else
  139. hNGUIMenuScript.NGUIMenuScriptEnabled(false);
  140. bGamePaused = false;
  141. iPauseStatus = 0;
  142. }
  143. else if (iPauseStatus == 4)
  144. {
  145. if (isCustomMenuEnabled())
  146. hMenuScriptCS.setMenuScriptStatus(true);
  147. else
  148. hNGUIMenuScript.NGUIMenuScriptEnabled(true);
  149. bGamePaused = true;
  150. LoginManager.Instance.GreatingMessages.Show();
  151. iPauseStatus = 2;
  152. }
  153. if(iDeathStatus==1)//call death menu
  154. {
  155. Debug.Log("if(iDeathStatus==1)");
  156. //LifeManager.Consume();
  157. hPowerupsMainControllerCS.deactivateAllPowerups(); //deactivate if a powerup is enabled
  158. //add bg
  159. iDeathStatus = 2;
  160. Lost = true;
  161. //end bg
  162. /*if (LifeManager.Lifes <= 0)
  163. {
  164. iDeathStatus = 2;
  165. }
  166. else
  167. {
  168. Debug.Log(iDeathStatus);
  169. iDeathStatus = 2;
  170. }*/
  171. }
  172. else if (iDeathStatus == 2)
  173. {
  174. if (isCustomMenuEnabled())//if custom menu is in use
  175. {
  176. hMenuScriptCS.setMenuScriptStatus(true);
  177. hMenuScriptCS.displayGameOverMenu(); //display the Game Over menu
  178. }
  179. else //if NGUI menu is in use
  180. {
  181. hNGUIMenuScript.NGUIMenuScriptEnabled(true);
  182. //Debug.Log();
  183. hNGUIMenuScript.ShowMenu(NGUIMenuScript.NGUIMenus.CodeEnter);
  184. hNGUIMenuScript.CurStatePopup = NGUIMenuScript.StatesMenuForPopup.GameOver;
  185. if (Lost)
  186. {
  187. LostLife();
  188. Lost = false;
  189. UIEnergy.Instance.Restore();
  190. InGameScriptCS.Instance.InvokeResurrection();
  191. hNGUIMenuScript.toggleHUDGroupState(false);
  192. //hPlayerSidesColliderScriptCS.InvokeResurrection();
  193. //hPlayerFrontColliderScriptCS.InvokeResurrection();
  194. //CurrentEnergy = 500000;
  195. //PlayerController.Instance.Alive();
  196. //hControllerScriptCS.Active();
  197. }
  198. var curFirst = PlayerPrefs.GetInt("EnterFirst");
  199. curFirst++;
  200. //Debug.Log(curFirst);
  201. PlayerPrefs.SetInt("EnterFirst", curFirst);
  202. PlayerPrefs.Save();
  203. }
  204. iDeathStatus = 0;
  205. }
  206. else if (iDeathStatus == 3)
  207. {
  208. //iDeathStatus = 0;
  209. }
  210. //Debug.Log("Debug.Log(iDeathStatus);" +iDeathStatus );
  211. if (bGamePaused == true)
  212. return;
  213. }//end of Update()
  214. public bool Lost;
  215. void LostLife()
  216. {
  217. Debug.Log("LostLife");
  218. NotificationCenter.Post(NotificationType.ShowEnterCode);
  219. }
  220. /*
  221. * FUNCTION: Pause the game
  222. * CALLED BY: ControllerScript.getClicks()
  223. */
  224. public void pauseGame()
  225. {
  226. if (!hControllerScriptCS.isMechAnimEnabled()) //if legacy animaitons are enabled
  227. {
  228. hControllerScriptCS.togglePlayerAnimation(false);//stop character animations
  229. }
  230. bGamePaused = true;//signal all scripts to pause
  231. iPauseStatus = 1;
  232. hSoundManagerCS.stopAllSounds();//stop all sounds
  233. PlayerPrefs.Save();//save changes in player prefs
  234. }
  235. public void Pause()
  236. {
  237. bGamePaused = true;//signal all scripts to pause
  238. }
  239. public void Resume()
  240. {
  241. bGamePaused = false;
  242. }
  243. public void LoadStartSanta()
  244. {
  245. StartCoroutine(LoadStart());
  246. }
  247. private IEnumerator LoadStart()
  248. {
  249. yield return new WaitForSeconds(0.0f);
  250. SceneManager.LoadSceneAsync("Santa");
  251. }
  252. public void PendingResurection()
  253. {
  254. if (!LifeLost)
  255. {
  256. LifeLost = true;
  257. //Debug.Log("PendingResurection");
  258. if (LifeManager.Lifes <= 1)
  259. {
  260. PlayerControllerLevels.Instance.AllDistance = PlayerControllerLevels.Instance.AllDistance + (int)hControllerScriptCS.getCurrentMileage();
  261. PlayerControllerLevels.Instance.AllGifts = PlayerControllerLevels.Instance.AllGifts + hPowerupsMainControllerCS.getCurrencyUnits();
  262. PlayerControllerLevels.Instance.AllPoint = PlayerControllerLevels.Instance.AllDistance + PlayerControllerLevels.Instance.AllGifts * 3 + TooltipLastterController.Instance.PontWords;
  263. DistanceGameOver.text = PlayerControllerLevels.Instance.AllDistance.ToString() + "m";
  264. GiftsGameOver.text = PlayerControllerLevels.Instance.AllGifts.ToString();
  265. PointsGameOver.text = PlayerControllerLevels.Instance.AllPoint.ToString();
  266. bGamePaused = true;//signal all scripts to pause
  267. //if (LoginManager.Instance.CountEnterCode <= LoginManager.Instance.MaxEnterCode)
  268. //if(RegisterCodeMIX.CanRegisterMore)
  269. //{
  270. // NotificationCenter.Post(NotificationType.ShowEnterCode);
  271. // //NGUIMenuScript.Instance.toggleHUDGroupState(true, true);
  272. //}
  273. //else
  274. //{
  275. // if (PlayerPrefs.GetInt("GetCoupon") == 1)
  276. // {
  277. // // Debug.Log("CouponGetEnterNumber.Show()");
  278. // LoginManager.Instance.CouponGetEnterNumber.Show();
  279. // NGUIMenuScript.Instance.CurStatePopup = NGUIMenuScript.StatesMenuForPopup.GameOver;
  280. // hNGUIMenuScript.ShowMenu(NGUIMenuScript.NGUIMenus.GameOver);
  281. // NGUIMenuScript.Instance.toggleHUDGroupState(false, false);
  282. // }
  283. // else
  284. // {
  285. // NGUIMenuScript.Instance.CurStatePopup = NGUIMenuScript.StatesMenuForPopup.GameOver;
  286. // hNGUIMenuScript.ShowMenu(NGUIMenuScript.NGUIMenus.GameOver);
  287. // NGUIMenuScript.Instance.toggleHUDGroupState(false, false);
  288. // }
  289. //}
  290. var counter = PlayerPrefs.GetInt("AdCounter");
  291. if (counter < GameConstants.MAX_ADD_LIFE)
  292. {
  293. LoginManager.Instance.GameOverVideoAdsLife.Show();
  294. }
  295. else
  296. {
  297. InGameScriptCS.Instance.UpdateScore();
  298. NGUIMenuScript.Instance.CurStatePopup = NGUIMenuScript.StatesMenuForPopup.GameOver;
  299. hNGUIMenuScript.ShowMenu(NGUIMenuScript.NGUIMenus.GameOver);
  300. PlayerPrefs.SetInt("AdCounter", 0);
  301. PlayerPrefs.Save();
  302. NGUIMenuScript.Instance.toggleHUDGroupState(false, false);
  303. }
  304. //NGUIMenuScript.Instance.ShowMenu(NGUIMenuScript.NGUIMenus.CodeEnter);
  305. //NGUIMenuScript.Instance.toggleHUDGroupState(true, true);
  306. PlayerController.Instance.Death();
  307. SoundManagerCS.Instance.GameOverMusic();
  308. LifeManager.Consume();
  309. hSoundManagerCS.stopAllSounds();//stop all sounds
  310. PlayerPrefs.Save();//save changes in player prefs
  311. //var top = GameObject.Find("fbTOP100").GetComponent<fbtop>();
  312. //var distance = PlayerControllerLevels.Instance.AllDistance;
  313. //var gifts = PlayerControllerLevels.Instance.AllGifts;
  314. //top.AddScore(distance, gifts, TooltipLastterController.Instance.PontWords);
  315. return;
  316. }
  317. if (!hControllerScriptCS.isMechAnimEnabled()) //if legacy animaitons are enabled
  318. {
  319. hControllerScriptCS.togglePlayerAnimation(false); //stop character animations
  320. }
  321. bGamePaused = true;//signal all scripts to pause
  322. NGUIMenuScript.Instance.ShowMenu(NGUIMenuScript.NGUIMenus.RaceEnd);
  323. NGUIMenuScript.Instance.toggleHUDGroupState(true, true);
  324. PlayerController.Instance.Death();
  325. LifeManager.Consume();
  326. SoundManagerCS.Instance.GameOverMusic();
  327. hSoundManagerCS.stopAllSounds();//stop all sounds
  328. PlayerPrefs.Save();//save changes in player prefs
  329. }
  330. StartCoroutine(LifeResurection());
  331. }
  332. private IEnumerator LifeResurection()
  333. {
  334. yield return new WaitForSeconds(1);
  335. LifeLost = false;
  336. }
  337. public bool LifeLost;
  338. public void InvokeResurrection()
  339. {
  340. Resurected = true;
  341. bGamePaused = false;
  342. NGUIMenuScript.Instance.ShowCandle();
  343. NGUIMenuScript.Instance.toggleHUDGroupState(true,true);
  344. //Analitics.Rescue();
  345. }
  346. /*
  347. * FUNCTION: start the gameplay and display all related elements
  348. * CALLED BY: MenuScript.MainMenuGui()
  349. * MenuScript.MissionsGui()
  350. */
  351. public int Level;
  352. public bool LevelForAchivment;
  353. public void launchGame()
  354. {
  355. GetComponent<ElementsGeneratorCS>().SpawnLetter = true;
  356. iMenuStatus = 0;
  357. bGamePaused = true;//tell all scripts to resume
  358. NGUIMenuScript.Instance.NGUIMenuScriptEnabled(true);
  359. if (isCustomMenuEnabled())//if custom menu is in use
  360. hMenuScriptCS.showHUDElements();
  361. else//if NGUI menu is in use
  362. hNGUIMenuScript.toggleHUDGroupState(true);
  363. if (PlayerPrefs.GetInt("Level") >= 4)
  364. {
  365. LaunchGameStart();
  366. LevelForAchivment = false;
  367. }
  368. else
  369. {
  370. if (KHD.FlurryAnalyticsTest.Instance != null)
  371. {
  372. switch (Level)
  373. {
  374. case 1:
  375. KHD.FlurryAnalyticsTest.Instance.GameStartLevel1();
  376. break;
  377. case 2:
  378. KHD.FlurryAnalyticsTest.Instance.GameStartLevel2();
  379. break;
  380. case 3:
  381. KHD.FlurryAnalyticsTest.Instance.GameStartLevel3();
  382. break;
  383. }
  384. }
  385. if (Level >= PlayerPrefs.GetInt("Level"))
  386. {
  387. LoginManager.Instance.StartLevelMessages.Show();
  388. LoginManager.Instance.StartLevelMessages.GetComponent<StartLevelMessage>().OnEnable();
  389. LevelForAchivment = true;
  390. }
  391. else
  392. {
  393. LaunchGameStart();
  394. LevelForAchivment = false;
  395. }
  396. }
  397. //hControllerScriptCS.launchGame();//tell the ControllerScriptCS to start game
  398. //hCameraControllerCS.launchGame();
  399. hNGUIMenuScript.toggleHUDGroupState(true,true);
  400. //hNGUIMenuScript.startResumeGameCounter();
  401. //StartCoroutine(LaunchTimerToGame());
  402. //tell the CameraControllerCS to start game
  403. //StartCoroutine(LaunchTimerToGame());
  404. //count how many time the game has started
  405. KHD.FlurryAnalyticsTest.Instance.GamePlayed();
  406. }
  407. public void UpdateScore()
  408. {
  409. PlayerControllerLevels.Instance.AllDistance = PlayerControllerLevels.Instance.AllDistance + (int)hControllerScriptCS.getCurrentMileage();
  410. PlayerControllerLevels.Instance.AllGifts = PlayerControllerLevels.Instance.AllGifts + hPowerupsMainControllerCS.getCurrencyUnits();
  411. PlayerControllerLevels.Instance.AllPoint = PlayerControllerLevels.Instance.AllDistance + PlayerControllerLevels.Instance.AllGifts * 3 + TooltipLastterController.Instance.PontWords;
  412. DistanceGameOver.text = PlayerControllerLevels.Instance.AllDistance.ToString() + "m";
  413. GiftsGameOver.text = PlayerControllerLevels.Instance.AllGifts.ToString();
  414. PointsGameOver.text = PlayerControllerLevels.Instance.AllPoint.ToString();
  415. var top = GameObject.Find("fbTOP100").GetComponent<fbtop>();
  416. var distance = PlayerControllerLevels.Instance.AllDistance;
  417. var gifts = PlayerControllerLevels.Instance.AllGifts;
  418. top.AddScore(distance, gifts, TooltipLastterController.Instance.PontWords);
  419. }
  420. public void LaunchGameStart()
  421. {
  422. hNGUIMenuScript.startResumeGameCounter();
  423. StartCoroutine(LaunchTimerToGame());
  424. }
  425. private bool startTimer;
  426. IEnumerator LaunchTimerToGame()
  427. {
  428. if (iPauseStatus != 4)
  429. {
  430. }
  431. startTimer = true;
  432. hCameraControllerCS.launchGame();
  433. yield return new WaitForSeconds(3f);
  434. if (hNGUIMenuScript.getCurrentMenu() != NGUIMenuScript.NGUIMenus.PauseMenu)
  435. {
  436. bGamePaused = false;
  437. startTimer = false;
  438. NGUIMenuScript.Instance.NGUIMenuScriptEnabled(true);
  439. hMissionsControllerCS.incrementMissionCount(MissionsControllerCS.MissionTypes.StartGame);
  440. hGlobalAchievementControllerCS.incrementAchievementCount(GlobalAchievementControllerCS.GlobalAchievementTypes.StartGame);
  441. hControllerScriptCS.launchGame();
  442. }
  443. }
  444. /*
  445. * FUNCTION: Display death menu and end game
  446. * CALLED BY: ControllerScript.DeathScene()
  447. */
  448. public void setupDeathMenu()
  449. {
  450. Debug.Log("setupDeathMenu");
  451. bGameOver = true;
  452. bGamePaused = true;
  453. iDeathStatus = 1;
  454. UIEnergy.Instance.Save();
  455. PlayerPrefs.Save();//save changes in player prefs
  456. }//end of Setup Death Menu
  457. /*
  458. * FUNCTION: Execute a function based on button press in Pause Menu
  459. * CALLED BY: MenuScript.PauseMenu()
  460. */
  461. public void processClicksPauseMenu(MenuScriptCS.PauseMenuEvents index)
  462. {
  463. if (index == MenuScriptCS.PauseMenuEvents.MainMenu)
  464. Application.LoadLevel("_loader");
  465. else if (index == MenuScriptCS.PauseMenuEvents.Resume)
  466. {
  467. if (isCustomMenuEnabled())
  468. hMenuScriptCS.showHUDElements();
  469. else
  470. hNGUIMenuScript.toggleHUDGroupState(true);
  471. iPauseStatus = 3;
  472. if (!hControllerScriptCS.isMechAnimEnabled())//if legacy animation is enabled
  473. hControllerScriptCS.togglePlayerAnimation(true);//pause legacy animations
  474. }
  475. }//end of process click pause menu
  476. public GameObject _loader;
  477. /*
  478. * FUNCTION: Execute a function based on button press in Death Menu
  479. * CALLED BY: MenuScript.GameOverMenu()
  480. */
  481. public void procesClicksDeathMenu(MenuScriptCS.GameOverMenuEvents index)
  482. {
  483. /*if (index == MenuScriptCS.GameOverMenuEvents.Play)
  484. Application.LoadLevel("Santa");
  485. else if (index == MenuScriptCS.GameOverMenuEvents.Back)
  486. Application.LoadLevel("Santa");*/
  487. var curFirst = PlayerPrefs.GetInt("EnterFirst");
  488. Debug.Log(curFirst);
  489. if (curFirst == 1 || curFirst == 2 || curFirst == 3)
  490. {
  491. NGUIMenuScript.Instance.ShowMenu(NGUIMenuScript.NGUIMenus.FBInviteFriends);
  492. NGUIMenuScript.Instance.CloseMenu(NGUIMenuScript.NGUIMenus.GameOver);
  493. }
  494. else
  495. {
  496. AdManager.Instance.PlayVideoAd();
  497. }
  498. }//end of DM_ProcessClicks
  499. /*
  500. * FUNCTION: Is called when a collision occurs
  501. * CALLED BY: PlayerFrontColliderScript.OnCollisionEnter
  502. * processStumble()
  503. */
  504. public void collidedWithObstacle()
  505. {
  506. decrementEnergy(100); // deduct energy after collision
  507. hCameraControllerCS.setCameraShakeImpulseValue(5);
  508. }//end of Collided With Obstacle
  509. /*
  510. * FUNCTION: Pause game if application closed/ switched on device
  511. */
  512. void OnApplicationPause (bool pause)
  513. {
  514. //Debug.Log("Application Paused : "+pause);
  515. if(Application.isEditor==false)
  516. {
  517. if(bGamePaused==false&&pause==false)
  518. {
  519. pauseGame();
  520. }
  521. }
  522. }//end of OnApplication function
  523. //paused state
  524. public bool isGamePaused() { return bGamePaused; }
  525. //score
  526. public int getLevelScore() { return iLevelScore; }
  527. public void incrementLevelScore(int iValue) { iLevelScore += iValue; }
  528. //energy
  529. public int getCurrentEnergy() { return CurrentEnergy; }
  530. public bool isEnergyZero() { return (CurrentEnergy <= 0 ? true : false); }
  531. public void decrementEnergy(int iValue) { CurrentEnergy -= iValue; }
  532. public void EnergyAdd(int iValue) { CurrentEnergy += iValue; }
  533. //currency
  534. public int getCurrencyCount() { return iCurrencyCount; }
  535. public void alterCurrencyCount(int iVal) { iCurrencyCount+=iVal; }//increment or decrement currency
  536. //check if the custom or NGUI is enabled
  537. public bool isCustomMenuEnabled() { return customMenuEnabled; }
  538. public bool EnterCode = false;
  539. }