hi, as the title states im a new user and im learning c# as i go, now ive been having fun going through the BergZerg Hack & Slash tutorial (the coding tutorials are great for someone like me because he explains everything as he goes) but im adding little bits as i go, i added a cool little health globe instead of the horizontal bar in the tutorial which im very proud of.
Anyway im trying to do a very basic exp system ive got a bar which grows horizontally when exp is added, when exp > maxexp ive got it to reset back to 0, but i cant figure out where to put the code to add a level to my characters starting level, i tried it in a few places but either way ive inluded the script if someone can point me in the right direction id be appreciated beyond belief ive been staring at this for hours
using UnityEngine;
using System.Collections;
public class playerexp : MonoBehaviour
{
public Texture2D bar;
Rect bgRect;
Rect barRect;
Rect labelRect;
public int exp = 0;
public int maxExp = 44;
public int startlvl = 1;
public int curlvl = 1;
void Awake()
{
if (exp > maxExp)
curlvl++;
bgRect = new Rect(201, Screen.height-142, Screen.width - 402, 16);
barRect = new Rect(203, Screen.height-140, 0, 12);
}
void Start(){
}
void Update(){
expincrease (0);
}
void OnGUI()
{
GUIStyle myStyle = new GUIStyle(GUI.skin.label);
myStyle.fontSize = 10;
GUI.skin.label.alignment = TextAnchor.MiddleCenter;
GUI.Box (bgRect, GUIContent.none);
GUI.DrawTexture(barRect, bar);
GUI.Box(new Rect(30,Screen.height -39, 127, 14), ("EXP : " + exp.ToString() + " | " + maxExp.ToString()),myStyle);
GUI.depth = 0;
GUI.Box(new Rect(30,Screen.height -20, 127, 14), ("LEVEL : " + (startlvl * curlvl)),myStyle);
GUI.depth = 0;
}
public void expincrease(int adj){
exp +=adj;
if (exp > maxExp)
exp = 0;
//curlvl++;
if (exp > -1)
barRect.width = exp * bgRect.width / maxExp;
//TEST
if (exp < maxExp)
{ if (Input.GetKeyUp (KeyCode.KeypadPlus))
exp += 3;
}
}
}
