- Home /
C# Saving data to the player's computer
I am currently developing a racing game. I have just set up a script to give my players money when they finish first, second or third in a race and to count how much money they have, and display it on screen. I have been trying to find out how to save the amount of money a player has when they quite, and load it back up when they join again.
My Money Script
using UnityEngine;
using System.Collections;
public class CoinsAndShop : MonoBehaviour {
//Variables Start
public int money = 0;
public TextMesh guiMoney;
//Used to give money to the player when come first, second or third in a race
public bool raceFirst;
public bool raceSecond;
public bool raceThird;
//Variables End
//Displays Money
void Start(){
guiMoney.text = "Money : 0";
}
//Basic money script
void Update(){ //Updates once per frame
if (raceFirst == true) {
money += 1500;
raceFirst = false;
}
if (raceSecond == true) {
money += 1000;
raceSecond = false;
}
if (raceThird == true) {
money += 500;
raceThird = false;
}
}
I am very new to coding and game making, so any help is much appreciated. Thanks in advance for your help!
Answer by Landern · Jul 08, 2014 at 03:29 PM
Use PlayerPrefs if your saving doesn't require structure, its super simple, follow the examples in the link.
Your answer
Follow this Question
Related Questions
Earning Money 2 Answers
Player Money not working 1 Answer
Block Placing script error 1 Answer
How to call a function from a script in another scene 5 Answers
How To Add A Sprint Function? 1 Answer