Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEngine.SceneManagement;
  6.  
  7.  
  8. public class CoinScript : MonoBehaviour {
  9.  
  10. public static float scoreCoin;
  11. /////////////////////////
  12. public float astx_1;
  13. public float astx_2;
  14. public float astx_3;
  15. /////////////////////////
  16. public float winCoins;
  17. public float coin_num;
  18.  
  19. /////////////////////////
  20. public static float ballon_1;
  21. /////////////////////////
  22. public GameObject Panel_youwin;
  23. public GameObject Panel_youlose;
  24.  
  25.  
  26. Text coinscore;
  27.  
  28. public GameObject star1;
  29. public GameObject star2;
  30. public GameObject star3;
  31.  
  32. //reference to next button
  33.  
  34.  
  35. protected string currentLevel;
  36. protected int worldIndex;
  37. protected int levelIndex;
  38. public static bool isLevelComplete ;
  39.  
  40.  
  41. // Use this for initialization
  42. void Start () {
  43.  
  44. isLevelComplete = false;
  45. //get the star images
  46.  
  47. //disable the image component of all the star images
  48. star1.GetComponent<Image>().enabled = false;
  49. star2.GetComponent<Image>().enabled = false;
  50. star3.GetComponent<Image>().enabled = false;
  51.  
  52.  
  53. //disable the next button
  54. //save the current level name
  55. currentLevel = Application.loadedLevelName;
  56.  
  57. ballon_1=0;
  58. scoreCoin = coin_num;
  59. coinscore = GetComponent<Text>();
  60.  
  61. Panel_youwin.SetActive(false);
  62. Time.timeScale = 1f;
  63.  
  64. Panel_youlose.SetActive(false);
  65. Time.timeScale = 1f;
  66.  
  67.  
  68. }
  69.  
  70. void Update () {
  71. if (coinscore != null){
  72.  
  73. coinscore.text = "Score " + scoreCoin;
  74. }
  75.  
  76. if(ballon_1==astx_3&&Health.healthlife==3){
  77. star3.GetComponent<Image>().enabled = true;
  78. UnlockLevels(3);
  79. Panel_youwin.SetActive(true);
  80. Time.timeScale = 0f;
  81. }
  82.  
  83. if(ballon_1==astx_2&&Health.healthlife==2){
  84. star2.GetComponent<Image>().enabled = true;
  85. UnlockLevels(2);
  86. Panel_youwin.SetActive(true);
  87. Time.timeScale = 0f;
  88. }
  89.  
  90. if(ballon_1==astx_1&&Health.healthlife==1){
  91. star1.GetComponent<Image>().enabled = true;
  92. UnlockLevels(1);
  93. Panel_youwin.SetActive(true);
  94. Time.timeScale = 0f;
  95. }
  96.  
  97. if(Health.healthlife <= 0){
  98. Panel_youlose.SetActive(true);
  99. Time.timeScale = 0f;
  100.  
  101. }
  102. }
  103. protected void UnlockLevels (int stars){
  104.  
  105. //set the playerprefs value of next level to 1 to unlock
  106. //also set the playerprefs value of stars to display them on the World levels menu
  107. for(int i = 0; i < LockLevel.worlds; i++){
  108. for(int j = 1; j < LockLevel.levels; j++){
  109. if(currentLevel == "Level"+(i+1).ToString() +"." +j.ToString()){
  110. worldIndex = (i+1);
  111. levelIndex = (j+1);
  112. PlayerPrefs.SetInt("level"+worldIndex.ToString() +":" +levelIndex.ToString(),1);
  113. //check if the current stars value is less than the new value
  114. if(PlayerPrefs.GetInt("level"+worldIndex.ToString() +":" +j.ToString()+"stars")< stars)
  115. //overwrite the stars value with the new value obtained
  116. PlayerPrefs.SetInt("level"+worldIndex.ToString() +":" +j.ToString()+"stars",stars);
  117. }
  118. }
  119. }
  120.  
  121. }
  122.  
  123.  
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement