What this gives me is two buttons that look like this:
-0 +0
Which, since the integers move up and down together, is basically fine. What I’m looking for is a way of doing this:
0 +
Where the integer goes up or down depending on if the plus or minus sign was clicked. I’ve tried it as GUI.Label, GUI.Box, etc but nothing seems to work.
Ideally this will be used to tell my factories/etc how many of each unit to build, so I know I’ll need to figure that side out next.
here it is in C# should be easy to convert I only added 1 line
using UnityEngine;
using System.Collections;
public class NewBehaviourScript : MonoBehaviour
{
public int infCobuildCounter;
void OnGUI ()
{
GUI.Box (new Rect (80, 40, 100, 60), "Company");
if (GUI.Button (new Rect (85, 65, 20, 20), "-")) {
infCobuildCounter --;
}
if (GUI.Button (new Rect (155, 65, 20, 20), "+")) {
infCobuildCounter ++;
}
GUI.Label(new Rect(130, 65, 30, 20),infCobuildCounter.ToString());
}
}
I’ve never worked in C# before, what would I need to change to put that in JS? It looks almost entirely similar so I’m assuming the adjustment would be in these two lines
public int infCobuildCounter;
GUI.Label(new Rect(130, 65, 30, 20),infCobuildCounter.ToString());
That’s about what I figured. Any idea if I can limit this with a range? Ideal situation would be for it to be limited to a range of 0-3, and every 4 units to add to the next column.
Ok I’ve got that set. I’m still trying to figure out if RangeAttribute would be useful, and the entry in the Script Reference isn’t particularly informative.
What I would like to do is limit these three variables
var infCobuildCounter : int;
var infRegbuildCounter : int;
var infDivbuildCounter : int;
to a minimum of 0 (not able to go into the negatives) and a max of 3, with each 4th positive adding to the next column. So, for example, if infCobuildCounter = 3 and infRegbuildCounter = 0, clicking the “+” button on infCobuildCounter would reset that int to 0 and set infRegbuildCounter to 1.