We choose a type of character, "Character A", this loads Character A's inventory script (which is different from all other Character scripts (from B-Z). In Character A's inventory script (which has save and exit GUILayoutButtons) we click "Save" doing "something" with PlayerPrefs to only load Character A's script whenever we click Character A.
God I hope someone out there understands as I cannot figure out this easy concept..Here is some code to hopefully better convey the idea:
public class ChooseCharacter : MonoBehaviour {
// You'll notice that we load the Inventory script regardless of the decision
void OnGUI() {
if (GUI.Button (new Rect (600,100,200,20), "Character A")) {
Application.LoadLevel("Inventory");
}
if (GUI.Button (new Rect (600,160,200,20), "Character B")) {
Application.LoadLevel("Inventory");
}
if (GUI.Button (new Rect (600,220,200,20), "Character C")) {
Application.LoadLevel("Inventory");
}
if (GUI.Button (new Rect (600,280,200,20), "Character D")) {
Application.LoadLevel("Inventory");
}
}
}
So now with the Inventory Scene Loaded (which has the inventory script attached), it needs to make the distinction between character choices (from A-Z). So that when we click a character that we created, it shows its own inventory.
public class Inventory : MonoBehaviour {
void Start() {
if (we chose character A) { // use get Player Prefs but how?
// DON'T LOAD ANY OTHER SCRIPTS!
gameObject.AddComponent(typeof(CharacterA));
}
if (we chose character B) { // use get Player Prefs but how?
// DON'T LOAD ANY OTHER SCRIPTS!
gameObject.AddComponent(typeof(CharacterB));
}
if (we chose character C) { // use get Player Prefs but how?
// DON'T LOAD ANY OTHER SCRIPTS!
gameObject.AddComponent(typeof(CharacterC));
}
if (we chose character D) { // use get Player Prefs but how?
// DON'T LOAD ANY OTHER SCRIPTS!
gameObject.AddComponent(typeof(CharacterD));
}
if (we chose character E) { // use get Player Prefs but how?
// DON'T LOAD ANY OTHER SCRIPTS!
gameObject.AddComponent(typeof(CharacterE));
}
}
}
Here are the incredably shortend character scripts, in which the method "Save" needs to "Set" player prefs to something very specific so that the Inventory can load it and NOT get confused to the other character scripts..
public class CharacterA : MonoBehaviour {
public void Save() {
// Set Player Prefs to Something Specific for Char A!
// (MAKE DISTINCTION IN INVENTORY LOADER SCRIPT)
}
}
public class CharacterB : MonoBehaviour {
public void Save() {
// Set Player Prefs to Something Specific for Char B!
// (MAKE DISTINCTION IN INVENTORY LOADER SCRIPT)
}
}
public class CharacterC : MonoBehaviour {
public void Save() {
// Set Player Prefs to Something Specific for Char C!
// (MAKE DISTINCTION IN INVENTORY LOADER SCRIPT)
}
}
public class CharacterD : MonoBehaviour {
public void Save() {
// Set Player Prefs to Something Specific for Char D!
// (MAKE DISTINCTION IN INVENTORY LOADER SCRIPT)
}
}
public class CharacterE : MonoBehaviour {
public void Save() {
// Set Player Prefs to Something Specific for Char E!
// (MAKE DISTINCTION IN INVENTORY LOADER SCRIPT)
}
}
When I create a character and try to repeat that process, my original character (1st) is overwritten with the 2nd. If I try again, both characters are overwritten with the 3rd, and so on. I'm having a wild of a time trying to make the distinction..So I am befuddled and need some serious help.