Displaying percentage on GUI

Hi everybody

I want to make an exp bar for my RPG, and I want to display the current exp as a percentage of the needed exp. So I’ve made this script:

var maxexp = 50;

var curexp = 10;

var controlTexture : Texture2D;

function Update () {

if (curexp < 0) {

curexp = 0;


if (maxexp < curexp){

curexp = maxexp;



function OnGUI () {

if (maxexp >= 0){

GUI.Button(Rect (0,78,500,26), maxexp.ToString(), "box");


if (curexp >= 0){

GUI.Button(Rect (0,78,(curexp/maxexp*100),26), curexp/maxexp*100.ToString(), "box");



But when I add the script to a game object, it only displays the needed hp bar, and the bar displaying the percentage does only appear as a small bar at the left side of the screen, without displaying a number. And it also displays an error which says that the character T isn’t expected.

Please help me

You should use float division instead of integer division.