Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Help with general car game aspects

Discussion in 'General Discussion' started by phongle123, Apr 6, 2016.

  1. phongle123

    phongle123

    Joined:
    Mar 20, 2016
    Posts:
    17
    Hi, I'm making a car game with upgrade parts but I can't seem to make a saving system where it

    1) Saves what car you bought to bring from scene to scene
    2) Saves what kind of part performance increase or decrease on the car
    3) and bringing the horsepower, torque, etc. details from my driving scripts to the screen for users to see.

    Can someone tell me how to do it or if there's an asset available for this on the asset store. Thank You!
     
  2. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,605
  3. QFSW

    QFSW

    Joined:
    Mar 24, 2015
    Posts:
    2,905
    These are all pretty broad things rather than specific things you need help with
    Have you tried to do it, searching around when you hit a problem?
     
  4. Ostwind

    Ostwind

    Joined:
    Mar 22, 2011
    Posts:
    2,804
    None of those are really car game specific questions so if you have looking with the keyword car you will most likely find nothing. Best to start with the linked learn section and adapt the things you learn.
     
  5. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    2,183
    Think about what attributes each item has that you want to save. Then create a class (don't inherit from Monobehavior), and make the class [system.serializable]. You could then use the BinaryFormatter to save (serialize) the class to disk. You can also have a List<yourclass> which can be saved or read from disk.

    Another way to do it, is to write your data out to disk using the Xml writer and readers. Each platform has unique locations for saving app data so you'll also need to look those up (in the Unity docs or forums).
     
  6. JamesArndt

    JamesArndt

    Unity Technologies

    Joined:
    Dec 1, 2009
    Posts:
    2,912
    This might not be as awesome a solution as storing saved data on a server or something, but you could use PlayerPrefs to save information. Imagine each car as a number (integer). The Nissan GTR = 1, the VW Golf = 2, the Ford Mustang = 3. So now in your code when a car is clicked on (in a vehicle select menu) save out that selection as the number. For example, the player clicked on the VW Golf so now the car is represented by the number 2. When you move further along in the game, or at the level load for a track, instantiate the vehicle by checking up on the car number in Start()...so the code might ask internally, if the car is equal to 2, then instantiate the VW Golf. You can do this same thing for the performance level...Level 1 = 1, Level 2 = 2, Level 3 = 3. When some part of the UI is clicked or a slider is moved, you can increase this numerical level or decrease it. In code you can say if the performance number is 2, then this car is Level 2 for performance and has 350HP, 65% Tire Grip, etc. It's really about representing these things like performance, make and model, which track the player has progressed to, as a numeric value or even a string value (a string is text based).
     
  7. JamesArndt

    JamesArndt

    Unity Technologies

    Joined:
    Dec 1, 2009
    Posts:
    2,912
    I did some tutorials a while back, but the code will still work in Unity 5 as far as I know. The theory is the same. They store data as integers or floats into PlayerPrefs and then load them back up when we need to load something up like a certain color or level.

    Unity PlayerPrefs for Level Unlock Systems


    Creating a Vehicle Color Selection Menu