hi, i’ve created a script here tying to use player prefs so you can create a character and it will save, however im having a little problem. so far i’ve gotten player prefs to save what class and race you are in a array however im having trouble with CurSlotAmount CharAmount, everytime it laods the level it resets back to 0 and i really cant figure out why XD im sure its a simple mistake somwhere!
Race Class.js
private var RaceHuman = "Human";
private var RaceHumanDescription = "";
private var HumanBoxLoc : Vector2 = Vector2(1240,500);
private var RaceNarlon = "Narlon";
private var RaceNarlonDescription = "";
private var NarlonBoxLoc : Vector2 = Vector2(1240,460);
private var infoBox : Vector2 = Vector2 (240,460);
private var infoBoxX = 230;
private var infoBoxY = 120;
private var RaceBoxW = 90;
private var RaceBoxH = 30;
private var ClickedShamen = false;
private var ClickedWarrior = false;
static var CharAmountStore = 0;
var CharAmount = 0;
var NarlonClicked : boolean = false;
var humanClicked : boolean = false;
private var C1 : Vector2 = Vector2 (400,400);
private var C2 = 60;
private var C3 = 20;
private var H1 : Vector2 = Vector2 (800,70);
private var H2 = 140;
private var H3 = 30;
function Start () {
PlayerPrefs.GetInt("CharAmount");
PlayerPrefs.GetInt("CharacterTemplate.StatCurSlot");
print(PlayerPrefs.GetInt("CharacterTemplate.StatCurSlot"));
print(PlayerPrefs.GetInt("CharAmount"));
}
function OnGUI () {
if(GUI.Button(Rect(Screen.width - H1.x, Screen.height - H1.y, H2,H3), "Create")) {
CharAmount += 1;
PlayerPrefs.SetInt("CharAmount", CharAmount);
CharacterTemplate.StatCurSlot = CharAmount;
PlayerPrefs.SetInt("CharacterTemplate.StatCurSlot", CharacterTemplate.StatCurSlot);
CharacterTemplate.StatCurSlot = CharAmount;
LoadNextLevel ();
}
if(GUI.Button(Rect(Screen.width - HumanBoxLoc.x, Screen.height - HumanBoxLoc.y, RaceBoxW, RaceBoxH), RaceHuman)) {
humanClicked = true;
NarlonClicked = false;
BaseCharacter.Race = "Human";
}
if(GUI.Button(Rect(Screen.width - NarlonBoxLoc.x, Screen.height - NarlonBoxLoc.y, RaceBoxW, RaceBoxH),RaceNarlon)) {
humanClicked = false;
NarlonClicked = true;
BaseCharacter.Race = "Narlon";
}
if(humanClicked) {
GUI.Box(Rect(Screen.width - infoBox.x, Screen.height - infoBox.y, infoBoxX, infoBoxY), RaceHumanDescription);
BaseCharacter.Race = "Human";
if(GUI.Button(Rect(Screen.width - C1.x, Screen.height - C1.y, C2, C3), "Shamen")) {
ClickedShamen = true;
ClickedWarrior = false;
BaseCharacter.Class = "Shamen";
}
}
if(NarlonClicked) {
GUI.Box(Rect(Screen.width - infoBox.x, Screen.height - infoBox.y, infoBoxX, infoBoxY), RaceNarlonDescription);
BaseCharacter.Race = "Narlon";
if(GUI.Button(Rect(Screen.width - C1.x, Screen.height - C1.y, C2, C3), "Warrior")) {
ClickedShamen = false;
ClickedWarrior = true;
BaseCharacter.Class = "Warrior";
}
}
}
function LoadNextLevel () {
yield WaitForSeconds (1);
Application.LoadLevel ("CharacterSelect");
}
BaseCharacter.js
// 0 = null, 1 = race, 2 = class, 3 = Level, 4 = Admin
static var Race = "";
static var Class = "";
var CharacterBase = new Array ("null","Race","Class");
var RaceNP = Race;
var ClassNP = Class;
static var Level = 1;
var LevelNP = Level;
var CurRace = CharacterBase[1];
var CurClass = CharacterBase[2];
// Races
private var Human = "Human";
private var Narlon = "Narlon";
// clases
private var Warrior = "Warrior";
private var Shamen = "Shamen";
function Start () {
PlayerPrefs.GetString("Race");
PlayerPrefs.GetString("Class");
CharacterBase[3] = Level;
LevelNP = Level;
}
function Update () {
var RaceNP = Race;
var ClassNP = Class;
if(Input.GetKeyDown("l")) {
print(PlayerPrefs.GetString("RaceNP"));
print(PlayerPrefs.GetString("ClassNP"));
print(CharacterBase);
}
if(RaceNP == Human) {
CharacterBase[1] = Human;
PlayerPrefs.SetString("RaceNP", RaceNP);
}
if(RaceNP == Narlon) {
CharacterBase[1] = Narlon;
PlayerPrefs.SetString("RaceNP", RaceNP);
}
if(ClassNP == Warrior) {
CharacterBase[2] = Warrior;
PlayerPrefs.SetString("ClassNP", ClassNP);
}
if(Class == Shamen) {
CharacterBase[2] = Shamen;
PlayerPrefs.SetString("ClassNP", ClassNP);
}
RaceNP = Race;
}
CharacterTemplate.js
var CB : Vector2 = Vector2 (320,600);
var CB1 = 300;
var CB2 = 570;
var S1Char = "";
var S2Char = "";
var S3Char = "";
static var StatCurSlot = 0;
static var CharacterCount = new Array ();
var Slot1 = false;
var Slot2 = false;
var Slot3 = false;
var S1 : Vector2 = Vector2(310,550);
var S1x = 280;
var S1y= 40;
var S2 : Vector2 = Vector2(310,550);
var S2x = 280;
var S2y= 40;
var S3 : Vector2 = Vector2(310,550);
var S3x = 280;
var S3y= 40;
function Start () {
CharacterCount.length = 12;
PlayerPrefs.GetInt ("StatCurSlot");
print (PlayerPrefs.GetInt("StatCurSlot"));
StatChecker = StatCurSlot;
}
function Update () {
}
function OnGUI () {
GUI.Box(Rect(Screen.width - CB.x, Screen.height - CB.y, CB1,CB2), "Characters");
if(StatCurSlot == 1) {
if(GUI.Button(Rect(Screen.width - S1.x,Screen.height - S1.y, S1x,S1y), S1Char)) {
}
}
}
ClickCreate.js
var C1 : Vector2 = Vector2 (310,70);
var C2 = 280;
var C3 = 30;
function Update () {
}
function OnGUI () {
if(CharacterTemplate.StatCurSlot <= 12) {
if(GUI.Button(Rect(Screen.width - C1.x, Screen.height - C1.y, C2,C3), "Create Character")) {
Application.LoadLevel ("character_Creation");
}
}
}
Would really apprciate help! thanks guys!
edit: if i add a update to race class with CharAmount ++; it seems to add up and save the value. However if its added by the create button it seems to reset back to 0-1 which i really dont understand why :S