Answer the question
In order to leave comments, you need to log in
How to pass a Decimal number to another class?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;
public class GameHelper : MonoBehaviour {
private SaveData _SaveData = new SaveData();
public Text clickBoostText; // Текстовое поле с количеством $ за клик
public decimal clickBoost = 1; // Стандартное количество ; за клик
public Text balanceText; // Текстовое поле с балансом
public Text dollarsPerSecondText; // Текстовое поле с количиством $ в секунду
public decimal dollars; // Баланс
[Header("Shop")]
public int[] shopCosts; // Массив с ценами для магазина
public int[] bonusesClick; // Массив с бонусами за клик для магазина
public int[] bonusesSecond; // Массив с бонусами в секунду для магазина
public Text[] shop_prices; // Массив ценовыми полями для магазина
public Text[] shopItemsCountsText; // Массив с текстовыми полями количества улучшений для магазина
public int[] shopItemCounts; // Массив с количеством улучшений для магазина
public decimal addDollarsPerSec = 0;
/**********************************************************************************************************************************************************************
*
* CLASS METHODS
*
**********************************************************************************************************************************************************************/
private void Awake()
{
if (PlayerPrefs.HasKey("SaveData"))
{
_SaveData = JsonUtility.FromJson<SaveData>(PlayerPrefs.GetString("SaveData"));
Debug.Log(_SaveData.dollars);
}
}
private void OnApplicationQuit() // Метод срабатывающий при закрытии игры, сохранение
{
_SaveData.shopCosts = new int[shopCosts.Length];
_SaveData.bonusesClick = new int[bonusesClick.Length];
_SaveData.bonusesSecond = new int[bonusesSecond.Length];
_SaveData.shopItemCounts = new int[shopItemCounts.Length];
_SaveData.dollars = dollars;
_SaveData.boost = clickBoost;
for (int i = 0; i < shopCosts.Length; i++)
{
_SaveData.shopCosts[i] = shopCosts[i];
_SaveData.bonusesClick[i] = bonusesClick[i];
_SaveData.bonusesSecond[i] = bonusesSecond[i];
_SaveData.shopItemCounts[i] = shopItemCounts[i];
}
string saveDataJson = JsonUtility.ToJson(_SaveData);
Debug.Log(saveDataJson);
PlayerPrefs.SetString("SaveData", saveDataJson);
}
}
[Serializable]
class SaveData // Класс отвечающий за сохранение
{
public decimal dollars;
public decimal boost;
public int[] shopCosts;
public int[] bonusesClick;
public int[] bonusesSecond;
public int[] shopItemCounts;
}
{"shopCosts":[100,250,500,1000,1500],"bonusesClick":[1,0,0,5,0],"bonusesSecond":[0,2,10,0,25],"shopItemCounts":[0,0,0,0,0]}
Answer the question
In order to leave comments, you need to log in
As one former evangelist said: Unity is a platform of unfinished features. Hence the first rule of Unity development:
- try not to use what Unity provides.
choose any of the provided assets and use it without pain: https://assetstore.unity.com/search?q=json&k=json
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question