var curStam : float = 100.0;
var maxStam : float = 100.0;
var isSprinting : boolean = false;
var stamCooldown : boolean = false;
function OnGUI () {
GUI.Label(ResizeGUI(Rect(430,350,50,50)), "" + curStam);
if (GUI.Button(ResizeGUI(Rect(350,350,50,50)), "Run" && curStam > 0 && stamCooldown == false)) {
isSprinting = true;
}
else {
isSprinting = false;
}
if(isSprinting == true && curStam >= 0) {
curStam--;
}
if(isSprinting == false && curStam < 100.0) {
curStam++;
}
if(curStam == 0) {
stamCooldown = true;
}
if(curStam == 1.0) {
stamCooldown = false;
}
}
function ResizeGUI(_rect : Rect) : Rect
{
var FilScreenWidth = _rect.width / 800;
var rectWidth = FilScreenWidth * Screen.width;
var FilScreenHeight = _rect.height / 600;
var rectHeight = FilScreenHeight * Screen.height;
var rectX = (_rect.x / 800) * Screen.width;
var rectY = (_rect.y / 600) * Screen.height;
return Rect(rectX,rectY,rectWidth,rectHeight);
}
I’m trying to make a runescape style sprint bar, if you click on a button, it will activate sprinting so if you click somewhere, it sprints there, and when the curStam hits 0, you cant sprint anymore. Problem is the button, it worked with holding Shift in an update function, but I want it in a OnGUI.
Error is:
MissingMethodException: UnityEngine.GUI.Button
I tried to fix it by RepeatButton, does work tho. Any help greatly appreciated.
Ah thanks that fixed the error, but even with RepeatButton, it will only make the curStam change by -1, not keep going down to 0. How can I fix that?
– Madswintedited my answer, take a look.
– AeonIxionThanks! Now it works perfectly. Would you know how to add something so it wont make it lower so fast? I tried InvokeRepeating("curMax",1,1); that didn't do anything. Any tips regarding that? Thanks again !
– Madswintchange
– AeonIxioncurStam--tocurStam -= 0.1. you can increase/decrease it as fast or slow as you want. You could change the rate depending on the player's level for example :)Oh god another problem popped up. It starts at 100.01, and if I start it, and let it go down to 0, it goes to 0.0515 something. Why does it do that? Can I change that, without going back to int variable?
– Madswint