Search Unity

How to save a skin/sprite change even when restarting the game

Discussion in 'Scripting' started by impheris, Feb 17, 2019.

  1. impheris

    impheris

    Joined:
    Dec 30, 2009
    Posts:
    1,667
    Hi and good day.

    I have published a new game (techno runner) on android and ios, but it just have 1 spaceship and i want to give the player the option to chose between several spaceships (sprites) so, i already have a script that i place on a button and change the sprite for the one i want (like a normal menu to buy or unlock skins) in fact the same script is working with my other 3d game (bouncy color) but the problem is that when i close the game and open again, the player have the initial sprite (the standard initial skin) i mean, the skin or sprite change is not being saved.
    i want to save that the player changed the skin. I have searched for two days without any good awnser, maybe i do not know the exact term to search for it and im a little frustrated.

    Does anyone know any way to do that?

    Thanks for the patience and sorry for my english...
     
  2. WarmedxMints

    WarmedxMints

    Joined:
    Feb 6, 2017
    Posts:
    1,035
    playerThe quick and easy way is to use player prefs to store an int and select the sprite from an array based on the stored value.
     
  3. impheris

    impheris

    Joined:
    Dec 30, 2009
    Posts:
    1,667
    Thanks for your awnser, but, can you please explain a little bit?
    i have read on several pages that playerPrefs can not be used for those needs
     
  4. f2pallglory

    f2pallglory

    Joined:
    Jan 11, 2019
    Posts:
    25
    Maybe just save the data to external file and load it whenever you open the game? Like you create a variable to represent the the sprite used, simple example : int spriteCode = 1 represent skin 1, then you make sure to always load the spritecode in awake and make an if statement to load sprite based on the code loaded
     
  5. impheris

    impheris

    Joined:
    Dec 30, 2009
    Posts:
    1,667
    mmm, maybe, but, how can i save the data? i have to overwrite a psd file on runtime
     
  6. WarmedxMints

    WarmedxMints

    Joined:
    Feb 6, 2017
    Posts:
    1,035
    It is quite simple, you have an array of sprites for you ship. You set which sprite is in use from the value of an int which you store in player prefs. Simple load that int on startup and select which sprite to use.
     
  7. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,748
    If you'd like to sell skins, you should use inapp purchases. This way your players will be able to purchase skin, play offline with it, and transfer it to their another devices.
     
  8. impheris

    impheris

    Joined:
    Dec 30, 2009
    Posts:
    1,667
    Ok, i just realized that i do not need to change sprite, what i really need its to swap between prefabs, because, my sprites are animated, so...
    Do i have to create another post with another title or just modify this post?
     
  9. WarmedxMints

    WarmedxMints

    Joined:
    Feb 6, 2017
    Posts:
    1,035
    No, the solution is no different. Instead you have an array for prefabs and on start select which prefab to use based on the value of a stored int.
     
  10. impheris

    impheris

    Joined:
    Dec 30, 2009
    Posts:
    1,667
    Thanks for your patience brother...
    Solved...
     
    Last edited: Feb 20, 2019