Why does my button add 5 points instead of 1?
I've been trying to get this chunk of code to work for a while now. I'm trying to get it to just count up or down by 1 as long as there are enough availPoints which is set to a int of 5. Whenever i click the ui button attached to it, it dumps all points into the stat instead of just one at a time. I'm fairly new to all this and just following a tutorial that i'm attempting to translate to the new UI system. Any help would be appreciated. I've tried the code a few different ways and for the life of me cant figure it out.
public void DisplayStatIncreaseDecreaseButtons(int addStatsBeenClicked ){
for (int i = 0; i <= pointsToAllocate.Length; i++) {
if (pointsToAllocate[i] >= baseStatPoints[i] && availPoints > 0) {
if (addStatsBeenClicked == 0) {
minusButton.gameObject.SetActive (true);
Debug.Log ("Button Clicked" + pointsToAllocate[0]);
statPointNumText.text = pointsToAllocate[0].ToString();
pointsToAllocate[0] ++;
availPoints -= subPoints;
} else if (addStatsBeenClicked == 1) {
minusButton1.gameObject.SetActive (true);
Debug.Log ("Button Clicked" + pointsToAllocate[1]);
statPointNumText.text = pointsToAllocate[1].ToString();
pointsToAllocate[i]++;
--availPoints;
The code you have submitted is improper, as there are many brackets missing.
But if the increment is done inside the for loop then it will increment the value. try writing the increment statement "pointsToAllocate[0]++" outside the for loop.
Your answer