Can anyone tell me how to save double values? Unfortunately, it doesn’t work like that.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Shop : MonoBehaviour
{
public GameObject OpenShop;
public GameObject CloseShop;
public GameObject Clickerr;
public bool CreateJelly = false;
public bool Pressed = false;
public Text goldStats;
public static int slimeToSpawn = 0;
public Text[] GoldCostTexts;
public double[] GoldValue;
public double[] jellyAutoJelly;
public double[] jellyAutoJellyIncreasePerSec;
public GameObject[] jellies;
void Start()
{
Vector3 randomSpawnPosition = new Vector3(Random.Range(-2.4f, 2.4f), Random.Range(1.8f, -2.6f));
Instantiate(jellies[0], randomSpawnPosition, Quaternion.identity);
}
void Update()
{
goldStats.text = Clicker.goldCount.ToString();
if (CreateJelly == false)
{
CreateJelly = true;
StartCoroutine(JellyAutoJelly());
}
if (Pressed)
{
Vector2 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
transform.position = mousePos;
}
}
IEnumerator JellyAutoJelly()
{
for (int jellyIndex = 0; jellyIndex < jellyAutoJelly.Length; jellyIndex++)
{
Slimes.jellyCount += jellyAutoJelly[jellyIndex];
}
yield return new WaitForSeconds(1);
CreateJelly = false;
}
public void OpenShopOnClick()
{
OpenShop.SetActive(true);
CloseShop.SetActive(true);
Clickerr.SetActive(false);
}
public void CloseShopOnClick()
{
OpenShop.SetActive(false);
CloseShop.SetActive(false);
Clickerr.SetActive(true);
}
public void JellyPerSec(int jellyIndex)
{
if (slimeToSpawn <= 14 && Clicker.goldCount >= GoldValue[jellyIndex])
{
Debug.Log($"Spawn {jellies[jellyIndex].name}");
Vector3 randomSpawnPosition = new Vector3(Random.Range(-2.4f, 2.4f), Random.Range(1.8f, -2.6f));
Instantiate(jellies[jellyIndex], randomSpawnPosition, Quaternion.identity);
Clicker.goldCount -= GoldValue[jellyIndex];
GoldValue[jellyIndex] *= 1.3;
jellyAutoJelly[jellyIndex] += jellyAutoJellyIncreasePerSec[jellyIndex];
GoldCostTexts[jellyIndex].text = GoldValue[jellyIndex].ToString();
slimeToSpawn++;
}
}
private void SaveGame(int jellyIndex)
{
PlayerPrefs.SetInt("jellyAutoJellyIncreasePerSec", jellyAutoJellyIncreasePerSec[jellyIndex]);
}
}