Advertisement
Guest User

Untitled

a guest
Sep 12th, 2020
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.60 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6.  
  7. public class InstagramSkript : MonoBehaviour
  8. {
  9.    public SympathysUpping sympathysUpping;
  10.    public GameObject MainCamera;
  11.    public Image MainBttn;
  12.  
  13.    [Header("Инстаграм Маркет")]
  14.    public int[] SkinPrice;
  15.    public Image[] mainSkin;
  16.    public Text[] SkinPriceText;
  17.  
  18.    private Save sv = new Save();
  19.  
  20.     private void Awake()
  21.     {
  22.         if(PlayerPrefs.HasKey("SV"))
  23.         {
  24.             sv = JsonUtility.FromJson<Save>(PlayerPrefs.GetString("SV"));
  25.             for (int i = 0; i < SkinPrice[4]; i++)
  26.             {
  27.                 SkinPrice[i] = sv.SkinPrice[i];
  28.             }
  29.         }
  30.     }
  31.  
  32.     private void OnApplicationQuit()
  33.     {
  34.         sv.SkinPrice = new int[4];
  35.         for (int i = 0; i < SkinPrice[4]; i++)
  36.         {
  37.             sv.SkinPrice[i] = SkinPrice[i];
  38.         }
  39.         PlayerPrefs.SetString("SV", JsonUtility.ToJson(sv));
  40.     }
  41.  
  42.     void Start()
  43.     {
  44.         sympathysUpping = MainCamera.GetComponent<SympathysUpping>();
  45.     }
  46.  
  47.    public void PressSkin(int index)
  48.    {
  49.        if(sympathysUpping.sympathy >= SkinPrice[index])
  50.        {
  51.            sympathysUpping.sympathy = sympathysUpping.sympathy - SkinPrice[index];
  52.            SkinPrice[index] = 0;
  53.            MainBttn.sprite = mainSkin[index].sprite;
  54.            SkinPriceText[index].text = "Куплено";
  55.            PlayerPrefs.SetInt("SkinPrice", SkinPrice[index]);
  56.        }
  57.    }
  58.  
  59. }
  60. [Serializable]
  61.  public class Save
  62.    {
  63.        public int[] SkinPrice;
  64.    }
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement