I've been working on an saving system for my 2D RPG game, and I recently encountered an issue: my saving system uses PlayerPrefs, which I heard is supposed to be used for things such as settings. I've also heard that it isn't very secure and that people can exploit it. I was wondering whether there was a way to make my saving system more secure. Here's my inventory script that also holds the save function:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ItemInformation : MonoBehaviour
{
// These are the assets for the item to change
public Text nameText;
public Text descriptionText;
public Text regenText;
public Text amountText;
// This is the identifier for each item
public string identifier;
// These are the variables that change with the different items
public string itemName;
public string itemDescription;
public float itemRegeneration;
public int itemAmount;
// Starts on awake
void Awake()
{
// Function to change the object's information and such
nameText.text = itemName;
descriptionText.text = itemDescription;
regenText.text = "HEALS " + itemRegeneration + "HP";
// Loads game data
LoadDataIfNeeded();
}
// Function to save game data
public void SaveData()
{
string jsonString = JsonUtility.ToJson(this);
PlayerPrefs.SetString(identifier, jsonString);
PlayerPrefs.Save();
}
// Loads data if needed
public void LoadDataIfNeeded()
{
if (PlayerPrefs.HasKey(identifier))
{
string jsonInstance = PlayerPrefs.GetString(identifier);
JsonUtility.FromJsonOverwrite(jsonInstance, this);
}
else
{
SaveData();
}
}
// Updates on every frame
void Update()
{
// Shows amount of item left
amountText.text = "HAVE:" + itemAmount;
}
}