I am trying to make a racing game. I have 10 cars and every car have attributes like speed, brake force, acceleration and handling. Player can upgrade cars with buttons. I have to save car upgrades and set the texts of buttons (like, Speed Level 1). I tried PlayerPrefs but I have so much data to save. My question is, which way I have to use for saving that data?
Asked
Active
Viewed 181 times
2 Answers
1
Create a class
public class CarAttributes{
private float speed;
private int levelNumber;
}
Create a variable which will store all data of the car
CarAttributes car1 = new CarAttributes();
car1.speed = 100.0f;
car1.levelNumber = 3;
....
PlayerPrefs.SetString( "playerCar1", JsonConvert.SerializeObject(car1) );
To load data use
CarAttributes car1 = JsonConvert.DeserializeObject<CarAttributes>( PlayerPrefs.GetString( "playerCar1" ) );
Kaushik Chandru
- 1,735
- 3
- 10
0
There is no one single question for this, saving data in unity is just like saving data in every running program. I'll try to enumerate some of the methods :
PlayerPrefs : As @KaushikChandru already answered you can use player prefs to save the data, just serialize them and save them as a String, and then you can deserialize them to get them back as objects.
File : Instead of using a PlayerPrefs you can use a File instead, here is a useful video that explains that (here )
Use a database (sql lite) : The second one would be to use a database (local or remote). I suggest using SQL Lite, here is a useful tutorial for that (here)
Abdelkrim Bournane
- 574
- 4
- 16