Hi guys i made a basic 3 character classes and right now i load game and it starts with the class i choose by code (Warrior/Wizard/Ranger) with correspondent stats. But now i create 3 buttons in my Start scene with a name of each class and wt i would like to know is how can i load the level with correspondent class by pressing in each of the image/buttons instead of doing it by code automaticaly. Ty
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
[System.Serializable]
public class BasicInfoChar
{
public BasicStats baseInfo;
public TypeCharacter typeChar;
}
public class PlayerStatsController : MonoBehaviour {
public static PlayerStatsController instance;
public int xpMultiply = 1; //easly get xp from mobs, the bigger the xmMultiply the more xp we take from mobs
public float xpLevel = 100; //initial xp
public float difficultFactor = 1.5f; //exponential multiplyer for next level
private float xpNextLevel; //xp needed for next level
public List<BasicInfoChar> baseCharacterInfo;
// Use this for initialization
void Start () {
instance = this;
DontDestroyOnLoad (gameObject);
Application.LoadLevel ("GamePlay");
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown (KeyCode.A))
AddXp (100);
if (Input.GetKeyDown (KeyCode.R))
PlayerPrefs.DeleteAll ();
}
public static void AddXp(float xpAdd){
float newXp = (GetCurrentXp() + xpAdd) * PlayerStatsController.instance.xpMultiply;
while (newXp >= GetNextXp ()) {
newXp -= GetNextXp();
AddLevel();
}
PlayerPrefs.SetFloat ("currentXp", newXp);
}
public static float GetCurrentXp(){
return PlayerPrefs.GetFloat("currentXp");
}
public static int GetCurrentLevel(){
return PlayerPrefs.GetInt("CurrentLevel");
}
public static void AddLevel(){
int newLevel = GetCurrentLevel () + 1;
PlayerPrefs.SetInt ("CurrentLevel", newLevel);
}
public static float GetNextXp() {
return PlayerStatsController.instance.xpLevel * (GetCurrentLevel()+1) * PlayerStatsController.instance.difficultFactor;
}
public static TypeCharacter GetTypeCharacter(){
int typeId = PlayerPrefs.GetInt ("TypeCharacter");
if (typeId == 0)
return TypeCharacter.Warrior;
else if (typeId == 1)
return TypeCharacter.Wizard;
else if (typeId == 2)
return TypeCharacter.Ranger;
//Default class
return TypeCharacter.Warrior;
}
public static void SetTypeCharacter(TypeCharacter newType){
PlayerPrefs.SetInt ("TypeCharacter", (int)newType);
}
public BasicStats GetBasicStats (TypeCharacter type){
foreach (BasicInfoChar info in baseCharacterInfo){
if(info.typeChar == type)
return info.baseInfo;
}
return baseCharacterInfo [0].baseInfo;
}
void OnGUI(){
GUI.Label(new Rect(0, 0, 100, 50), "Current Xp: " + GetCurrentXp());
GUI.Label (new Rect (0, 15, 100, 50), "Current Level: " + GetCurrentLevel ());
GUI.Label(new Rect(0, 30, 150, 50), "Xp Next Level: " + GetNextXp());
}
}
using UnityEngine;
using System.Collections;
[System.Serializable]
public class BasicStats
{
public float currentHp;
public float maxHP;
public float currentMana;
public float maxMana;
public int strength;
public int magic;
public int agility;
public int stamina;
public int baseDamage;
public int baseArmor;
}
public abstract class CharacterBase : MonoBehaviour
{
//Basic Attributes
public int currentLevel;
public BasicStats basicStats;
// Use this for initialization
protected void Start ()
{
}
// Update is called once per frame
protected void Update ()
{
}
}
using UnityEngine;
using System.Collections;
public enum TypeCharacter{Warrior = 0, Wizard = 1, Ranger = 2}
public class PlayerBehavior : CharacterBase
{
private TypeCharacter type;
// Use this for initialization
protected void Start ()
{
base.Start ();
PlayerStatsController.SetTypeCharacter (TypeCharacter.Wizard);
currentLevel = PlayerStatsController.GetCurrentLevel ();
type = PlayerStatsController.GetTypeCharacter ();
basicStats = PlayerStatsController.instance.GetBasicStats (type);
}
}