- Home /
RPG Levelling Script using GUI Text help
I am trying to modify an old script I have meant for showing and modifying a score that the player gets from destroying gameobjects into a levelling up script. So far the script works find for showing the current experience and even works with levlling up, but only up to level 2. Once level 2 is reached then the level up script ceases to work in that it stops changing the experience needed to level up and level when the current exp is greater than or equal to the experience needed. Here is the code that I have so far (sorry for the remnants of the old script cluttering it up):
var hitTag = "bullet";
var hitName = "bullet";
var points = 10;
static var current_xp = 0;
var EXP_TO_LEVEL = 100;
var user_level = 1;
var exp_text : GUIText;
var level_text : GUIText;
var modify_exp = 1.5f;
var xp_given = 10;
function Update () {
}
function
ScorePoints()
{
gameObject.FindWithTag("Player").SendMessage("ScorePoints", points);
}
function addxp()
{
gameObject.FindWithTag("Player");
current_xp += xp_given;
if(current_xp >= EXP_TO_LEVEL)
{
user_level++;
EXP_TO_LEVEL = Mathf.FloorToInt(EXP_TO_LEVEL * user_level * modify_exp);
}
}
function updatetexts()
{
exp_text.text = (current_xp.ToString() + "/" + EXP_TO_LEVEL.ToString());
level_text.text = ("Level: " + user_level.ToString());
}
function
OnTriggerEnter(col : Collider)
{
if ((col.gameObject.tag == hitTag) || (col.gameObject.name == hitName))
{
Destroy(col.gameObject);
Destroy(gameObject);
Debug.Log("Trigger " + col.gameObject.tag);
addxp();
updatetexts();
}
}
function
OnCollisionEnter(col : Collision)
{
Debug.Log("BBBB Collision " + col.gameObject.tag);
if ((col.gameObject.tag == hitTag) || (col.gameObject.name == hitName))
{
Destroy(col.gameObject);
Destroy(gameObject);
Debug.Log("AAAAA Collision " + col.gameObject.tag);
current_xp++;
user_level++;
addxp();
updatetexts();
EXP_TO_LEVEL++;
}
}
Sheesh...that is one draconian XP system. You do realize the xp needed to level will look about like this: 100, 300, 1350, ~7000, etc. You might want to rethink that a bit. :)
But to the problem at hand: I notice that you're incrementing level each time the player hits an object (in OnCollisionEnter()). Seems like all of those increments should be removed, as they are all handled inside addxp().
Can you clarify what exactly is going wrong? Have you set a breakpoint inside of addxp()? Does the XP continue to climb?
You make a good point about that XP system. I had a C++ program run the math and it would be too ridiculous just by level 20. What the problem is that once level 2 is reached, I can keep gaining on the current_exp side, but once it becomes greater than or equal to the EXP_TO_LEVEL to get to level 3 it never turns over to the level 3. Or at least it didn't. I actually fixed the code and got it working by changing EXP_TO_LEVEL and user_level to static variables. I don't know why that made a difference but it did.
What would be suggested about the levelling algorithm to be less... draconian?
I think he means it would be way too long to get to the higher levels, that the increase of experience needed is too high. Just make it only like 10-20 percent harder than the last level, and make tougher baddies (that you only fight in harder levels) worth more xp.
$$anonymous$$D_Reptile's got it. So like if level 1 is 100, then level 2 is 220 (total XP), and level 3 is like 360. Basically just keep track of how much XP it is to get from level to level, and multiply that by 1.2 each time or something.
Congratulations on figuring out your solution.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
GUIText dissapear after a few seconds 2 Answers
Score System help 1 Answer
Climbing script 0 Answers
My character will fall through the floor with this script:... 1 Answer