- Home /
Question by
Red Sentinel · Jun 22, 2013 at 01:52 AM ·
javascriptguivalueaddsubtract
Setting the value of a var to the value of another
Hi everyone. I am having a problem of setting the value of one variable to the value of another.
This is my script:
var MaxArmourValue = 3;
var MinArmourValue = 1;
var CurrentArmourValue = 1;
var HelmSelection = CurrentArmourValue;
function OnGUI(){
GUI.Box (Rect (420,10,250,90), "Helmet "+ HelmSelection);
if (GUI.Button (Rect (600, 20, 50, 20), ">")) {
HelmSelection +=CurrentArmourValue;
}
if (HelmSelection > MaxArmourValue){
HelmSelection = MinArmourValue;
}
else if (HelmSelection < MinArmourValue); {
HelmSelection = MaxArmourValue;
}
if (GUI.Button (Rect (440, 20, 50, 20), "<")) {
HelmSelection -=CurrentArmourValue;
}
if (GUI.Button (Rect (495, 50, 100, 20), "Accept")) {
}
}
What I want to do is when the > or < buttons are pressed, the rectangle will show "Helmet 1/2/3" etc. This works but I don't know how to stop the values from going over 3 and below 1. All help is appreciated.
Comment
Answer by RoRoah · Jun 22, 2013 at 03:43 AM
just guessing but try this :
var MaxArmourValue = 3;
var MinArmourValue = 1;
var CurrentArmourValue = 1;
var HelmSelection = CurrentArmourValue;
function OnGUI(){
GUI.Box (Rect (420,10,250,90), "Helmet "+ HelmSelection);
if (GUI.Button (Rect (600, 20, 50, 20), ">")) {
HelmSelection +=CurrentArmourValue;
if (HelmSelection > MaxArmourValue){
HelmSelection = MinArmourValue;
}
}
if (GUI.Button (Rect (440, 20, 50, 20), "<")) {
HelmSelection -=CurrentArmourValue;
if (HelmSelection < MinArmourValue); {
HelmSelection = MaxArmourValue;
}
}
if (GUI.Button (Rect (495, 50, 100, 20), "Accept")) {
}
}
Your answer
Follow this Question
Related Questions
Setting Scroll View Width GUILayout 1 Answer
Gui Text Script 4 Answers
GUI Button Disappearing 1 Answer
GUI.Box NullReferenceException 0 Answers
Game Over GUI Question 2 Answers