thanks, but i still cant find the error, here is the code for character generator and gamesettingsV2
using UnityEngine;
using System.Collections;
using System; //used for enum class
public class CharacterGenerator : MonoBehaviour {
private PlayerCharacter _toon;
private const int STARTING_POINTS = 350;
private const int MIN_STARTING_ATTRIBUTE_VALUE = 10;
private const int STARTING_VALUE = 50;
private int pointsLeft;
private const int OFFSET = 5;
private const int LINE_HEIGHT = 20;
private const int STAT_LABEL_WIDTH = 105;
private const int BASE_LABEL_WIDTH = 30;
private const int BUTTON_WIDTH = 20;
private const int BUTTON_HEIGHT = 20;
private int statStartingPos = 40;
public GUISkin mySkin;
public GameObject playerPrefab;
public float delayTimer = .25f;
private float _lastClick = 0;
// Use this for initialization
void Start () {
GameObject pc = Instantiate(playerPrefab, Vector3.zero, Quaternion.identity) as GameObject;
pc.name = "Player";
_toon = pc.GetComponent<PlayerCharacter>();
pointsLeft = STARTING_POINTS;
for(int cnt = 0; cnt < Enum.GetValues(typeof(AttributeName)).Length; cnt++) {
_toon.GetPrimaryAttribute(cnt).BaseValue = STARTING_VALUE;
pointsLeft -= (STARTING_VALUE - MIN_STARTING_ATTRIBUTE_VALUE);
}
_toon.StatUpdate();
}
// Update is called once per frame
void Update () {
}
void OnGUI() {
GUI.skin = mySkin;
DisplayName();
DisplayPointsLeft();
DisplayAttributes();
DisplayVitals();
DisplaySkills();
if(_toon.Name != "" pointsLeft < 1)
DisplayCreateButton();
// if(_toon.Name == "" || pointsLeft > 0)
// DisplayCreateLabel();
// else
// DisplayCreateButton();
}
private void DisplayName() {
GUI.Label(new Rect(10, 10, 50, 25), "Name:");
_toon.Name = GUI.TextField(new Rect(65, 10, 100, 25), _toon.Name);
}
private void DisplayAttributes() {
for(int cnt = 0; cnt < Enum.GetValues(typeof(AttributeName)).Length; cnt++) {
GUI.Label(new Rect(OFFSET, statStartingPos + (cnt * LINE_HEIGHT), STAT_LABEL_WIDTH, LINE_HEIGHT), ((AttributeName)cnt).ToString());
GUI.Label(new Rect(STAT_LABEL_WIDTH + OFFSET, statStartingPos + (cnt * LINE_HEIGHT), BASE_LABEL_WIDTH, LINE_HEIGHT), _toon.GetPrimaryAttribute(cnt).AdjustedBaseValue.ToString());
if(GUI.RepeatButton(new Rect(OFFSET + STAT_LABEL_WIDTH + BASE_LABEL_WIDTH,statStartingPos + (cnt * BUTTON_HEIGHT), BUTTON_WIDTH, BUTTON_HEIGHT), "-")) {
if(Time.time - _lastClick > delayTimer){
if(_toon.GetPrimaryAttribute(cnt).BaseValue > MIN_STARTING_ATTRIBUTE_VALUE) {
_toon.GetPrimaryAttribute(cnt).BaseValue--;
pointsLeft++;
_toon.StatUpdate();
}
_lastClick = Time.time;
}
}
if(GUI.RepeatButton(new Rect(OFFSET + STAT_LABEL_WIDTH + BASE_LABEL_WIDTH + BUTTON_WIDTH, statStartingPos + (cnt * BUTTON_HEIGHT), BUTTON_WIDTH, BUTTON_HEIGHT), "+")) {
if(Time.time - _lastClick > delayTimer) {
if(pointsLeft > 0) {
_toon.GetPrimaryAttribute(cnt).BaseValue++;
pointsLeft--;
_toon.StatUpdate();
}
_lastClick = Time.time;
}
}
}
}
private void DisplayVitals() {
for(int cnt = 0; cnt < Enum.GetValues(typeof(VitalName)).Length; cnt++) {
GUI.Label(new Rect(OFFSET, statStartingPos + ((cnt + 7) * LINE_HEIGHT), STAT_LABEL_WIDTH, LINE_HEIGHT), ((VitalName)cnt).ToString() );
GUI.Label(new Rect(OFFSET + STAT_LABEL_WIDTH, statStartingPos + ((cnt + 7) * LINE_HEIGHT), BASE_LABEL_WIDTH, LINE_HEIGHT), _toon.GetVital(cnt).AdjustedBaseValue.ToString());
}
}
private void DisplaySkills() {
for(int cnt = 0; cnt < Enum.GetValues(typeof(SkillName)).Length; cnt++) {
GUI.Label(new Rect(OFFSET + STAT_LABEL_WIDTH + BASE_LABEL_WIDTH + BUTTON_WIDTH * 2 + OFFSET * 2, statStartingPos + (cnt * LINE_HEIGHT), STAT_LABEL_WIDTH, LINE_HEIGHT), ((SkillName)cnt).ToString() );
GUI.Label(new Rect(OFFSET + STAT_LABEL_WIDTH + BASE_LABEL_WIDTH + BUTTON_WIDTH * 2 + OFFSET * 2 + STAT_LABEL_WIDTH, statStartingPos + (cnt * LINE_HEIGHT), BASE_LABEL_WIDTH, LINE_HEIGHT), _toon.GetSkill(cnt).AdjustedBaseValue.ToString());
}
}
private void DisplayPointsLeft() {
GUI.Label(new Rect(250, 10, 100, 25), "Points Left: " + pointsLeft.ToString());
}
private void DisplayCreateLabel() {
// GUI.Label(new Rect( Screen.width/ 2 - 50, statStartingPos + (10 * LINE_HEIGHT), 100, LINE_HEIGHT), "Enter Name", "Button");
}
private void DisplayCreateButton() {
if(GUI.Button(new Rect(Screen.width/ 2 - 50, statStartingPos + (10 * LINE_HEIGHT), 100, LINE_HEIGHT), "Next")) {
// GameSettings gsScript = GameObject.Find("__GameSettings").GetComponent<GameSettings>();
//change the cur value of the vitals to the max modified value of that vital
UpdateCurVitalValues();
//save the character data
// gsScript.SaveCharacterData();
GamesettingsV2.SaveName( _toon.Name );
GamesettingsV2.SaveAttribute(AttributeName.Might, _toon.GetPrimaryAttribute( (int)AttributeName.Might ) );
Debug.Log( GamesettingsV2.LoadAttribute(AttributeName.Might).ToString() );
// Application.LoadLevel(GameSettings.levelNames [2]);
}
}
private void UpdateCurVitalValues() {
for(int cnt = 0; cnt < Enum.GetValues(typeof(VitalName)).Length; cnt++) {
_toon.GetVital(cnt).CurValue = _toon.GetVital(cnt).AdjustedBaseValue;
}
}
}
using UnityEngine;
using System.Collections;
public static class GamesettingsV2 {
private const string HAIR_COLOR = "Hair Color";
private const string HAIR_MESH = "Hair Mesh";
private const string NAME = "Player Name";
private const string BASE_VALUE = " - BASE VALUE";
private const string EXP_TO_LEVEL = " - EXP TO LEVEL";
static GamesettingsV2() {
}
public static void SaveHairColor( int index ) {
PlayerPrefs.SetInt( HAIR_COLOR, index );
Debug.Log ( HAIR_COLOR + " : " + index );
}
public static int LoadHairColor() {
return PlayerPrefs.GetInt( HAIR_COLOR, 0 );
}
public static void SaveHairMesh( int index ) {
PlayerPrefs.SetInt( HAIR_MESH , index );
}
public static int LoadHairMesh() {
return PlayerPrefs.GetInt( HAIR_MESH, 0 );
}
public static void SaveHair(int mesh, int color ) {
SaveHairColor( color );
SaveHairMesh( mesh );
}
public static void SaveName( string name ) {
PlayerPrefs.SetString(NAME, name);
}
public static string LoadName() {
return PlayerPrefs.GetString(NAME, "Anon");
}
public static void SaveAttribute( AttributeName name, Attribute attribute ) {
PlayerPrefs.SetInt(((AttributeName)name).ToString() + BASE_VALUE, attribute.BaseValue);
PlayerPrefs.SetInt(((AttributeName)name).ToString() + EXP_TO_LEVEL, attribute.ExpToLevel);
}
public static Attribute LoadAttribute( Attribute name ) {
Attribute att = new Attribute();
att.BaseValue = PlayerPrefs.GetInt(((Attribute)name).ToString() + BASE_VALUE, 0);
att.ExpToLevel = PlayerPrefs.GetInt(((AttributeName)name).ToString() + EXP_TO_LEVEL, Attribute.STARTING_EXP_COST);
return att;
}
public static void SaveAttributes( Attribute[] attribute ) {
}
public static Attribute[] LoadAttributes() {
Attribute[] att = { new Attribute(), new Attribute() };
return att;
}
public static void SaveVital( VitalName name, Vital vital ) {
}
public static Vital LoadVital( Vital name ) {
return new Vital();
}
public static void SaveVital( Vital[] vital ) {
}
public static Vital[] LoadVitals() {
Vital[] att = { new Vital(), new Vital() };
return att;
}
public static void SaveSkill( SkillName name, Skill skill ) {
}
public static Skill LoadSkill( Skill name ) {
return new Skill();
}
public static void SaveSkills( Skill[] skill ) {
}
public static Skill[] LoadSkills() {
Skill[] att = { new Skill(), new Skill() };
return att;
}
}