There are 4 sets of gameObject A,B,C,D and there are 4 sets of color red, black, white, brown and there is one trigger to check which gameobject has entered.
Now suppose A has entered the trigger and now i click on red, now the A gameobjects material is red.
Now when i click on save button this A gameobject with new rendermaterial should be saved.
So next time when i play the game i should be able to see the saved gameobject.
How to achieve this? I feel PlayersPrefs will be involved.
2 Answers
2Yes you could use PlayerPrefs. I would make each object have a unique name, and use that as the key. And each material should have a unique name, and use that name as the value, save the pref as a string. When you restart the game, read out each object name as the key and the value is the name of the material, then set the material from that.
I dont know how to use Key. So you are telling me for the colors give playerprefs.setint and for each object playerprefs.string ?
– united4lifeYou can use the PlayerPrefs class for that.
For each color of the gameobject set an int or string based on how yoy want to store it and give it an unique id or key like object1Color.
To this for everything you want to store from the gameobject for future use ingame.
Any idea how to achieve this...?
– united4lifeAs far as I know, there is no direct way to save the state of a game object while the game is running. Doing so would require you to overwrite the scene or the prefab file, whichever was used by the player to deserialize the game object. What you want is essentially saving and loading a game state. There are plenty of answered questions on how to that, like this one: http://answers.unity3d.com/questions/8480/how-to-scrip-a-saveload-game-option.html Look around the site, you might get a better idea of what you have to do to get your desired effect.
– hoy_smallfry