Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.SceneManagement;
- public class CoinScript : MonoBehaviour {
- public static float scoreCoin;
- /////////////////////////
- public float astx_1;
- public float astx_2;
- public float astx_3;
- /////////////////////////
- public float winCoins;
- public float coin_num;
- /////////////////////////
- public static float ballon_1;
- /////////////////////////
- public GameObject Panel_youwin;
- public GameObject Panel_youlose;
- Text coinscore;
- public GameObject star1;
- public GameObject star2;
- public GameObject star3;
- //reference to next button
- protected string currentLevel;
- protected int worldIndex;
- protected int levelIndex;
- public static bool isLevelComplete ;
- // Use this for initialization
- void Start () {
- isLevelComplete = false;
- //get the star images
- //disable the image component of all the star images
- star1.GetComponent<Image>().enabled = false;
- star2.GetComponent<Image>().enabled = false;
- star3.GetComponent<Image>().enabled = false;
- //disable the next button
- //save the current level name
- currentLevel = Application.loadedLevelName;
- ballon_1=0;
- scoreCoin = coin_num;
- coinscore = GetComponent<Text>();
- Panel_youwin.SetActive(false);
- Time.timeScale = 1f;
- Panel_youlose.SetActive(false);
- Time.timeScale = 1f;
- }
- void Update () {
- if (coinscore != null){
- coinscore.text = "Score " + scoreCoin;
- }
- if(ballon_1==astx_3&&Health.healthlife==3){
- star3.GetComponent<Image>().enabled = true;
- UnlockLevels(3);
- Panel_youwin.SetActive(true);
- Time.timeScale = 0f;
- }
- if(ballon_1==astx_2&&Health.healthlife==2){
- star2.GetComponent<Image>().enabled = true;
- UnlockLevels(2);
- Panel_youwin.SetActive(true);
- Time.timeScale = 0f;
- }
- if(ballon_1==astx_1&&Health.healthlife==1){
- star1.GetComponent<Image>().enabled = true;
- UnlockLevels(1);
- Panel_youwin.SetActive(true);
- Time.timeScale = 0f;
- }
- if(Health.healthlife <= 0){
- Panel_youlose.SetActive(true);
- Time.timeScale = 0f;
- }
- }
- protected void UnlockLevels (int stars){
- //set the playerprefs value of next level to 1 to unlock
- //also set the playerprefs value of stars to display them on the World levels menu
- for(int i = 0; i < LockLevel.worlds; i++){
- for(int j = 1; j < LockLevel.levels; j++){
- if(currentLevel == "Level"+(i+1).ToString() +"." +j.ToString()){
- worldIndex = (i+1);
- levelIndex = (j+1);
- PlayerPrefs.SetInt("level"+worldIndex.ToString() +":" +levelIndex.ToString(),1);
- //check if the current stars value is less than the new value
- if(PlayerPrefs.GetInt("level"+worldIndex.ToString() +":" +j.ToString()+"stars")< stars)
- //overwrite the stars value with the new value obtained
- PlayerPrefs.SetInt("level"+worldIndex.ToString() +":" +j.ToString()+"stars",stars);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement