Help with saving a character selection in unity.

Discussion in 'Game Development (Technical)' started by Cubee01, Nov 12, 2018.

Tags:
  1. Cubee01

    Cubee01 New Member

    Joined:
    Feb 13, 2017
    Messages:
    7
    Likes Received:
    0
    Hello

    I am working on a character selection menu and when the player buys a new charcter and dies playing that character the scene gets reloaded. And when the scene gets reloaded the charcter goes back to the original one. I am wondering if there is a way to save that charcter selection even when the scene gets reloaded.

    Here is the code that runs when the player buys a new character.

    Code:
     public void YellowPlaneSelect()
        {
            if (TheScore.thePoints >= yellowPlaneCost && yellowPlaneSave == 0)
            {
                Destroy(currentPlayer);
                GameObject newPlayer = Instantiate(yellowPlane);
                yellowPlaneSave = 1;
                PlayerPrefs.SetInt("yellowPlaneSave", yellowPlaneSave);
                PlayerPrefs.SetString("yellowPlaneText", Select);
                TheScore.thePoints -= yellowPlaneCost;
                PlayerPrefs.SetInt("Money", TheScore.thePoints);
                newPlayer.GetComponent<movemnt>().enabled = false;
                newPlayer = currentPlayer;
                characterSelect.SetActive(false);
            }
            else if (yellowPlaneSave == 1)
            {
                Destroy(currentPlayer);
                GameObject newPlayer = Instantiate(yellowPlane);
                newPlayer.GetComponent<movemnt>().enabled = false;
                newPlayer = currentPlayer;
                characterSelect.SetActive(false);
            }
            else if (TheScore.thePoints < yellowPlaneCost && yellowPlaneSave == 0)
            {
                Debug.Log("Not enough coins");
            }
            
        }
    I think I need to save the currentPlayer GameObject But I am unsure on how to do that. Or if there is another way to fix this.

    Thanks!
     

Share This Page

  • About Indie Gamer

    When the original Dexterity Forums closed in 2004, Indie Gamer was born and a diverse community has grown out of a passion for creating great games. Here you will find over 10 years of in-depth discussion on game design, the business of game development, and marketing/sales. Indie Gamer also provides a friendly place to meet up with other Developers, Artists, Composers and Writers.
  • Buy us a beer!

    Indie Gamer is delicately held together by a single poor bastard who thankfully gets help from various community volunteers. If you frequent this site or have found value in something you've learned here, help keep the site running by donating a few dollars (for beer of course)!

    Sure, I'll Buy You a Beer