Help with adjusting script.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class statroll : MonoBehaviour {

    public void RandomizeStats() {

    for(int x = 0; x < 20; x++)
    {
        int str = 5, agi = 5, inte = 5;
        int statroll = Random.Range(1,3);
        switch (statroll)
        {
        case 3:
            str++;
            break;
        case 2:
            agi++;
            break;
        case 1:
            inte++;
            break;
        default:
            Debug.LogError("Something went wrong, probbably with my Random.Range bounds!");
            x--;
            break;
        }
            Debug.Log("str=" + str + " :agi=" + agi + " :inte=" + inte);

    }

}
}

I know this is like the fifth thread I opened on this one annoying script, but I’m struggling with this.
Thanks to the help of some posters in these forums, I’ve been able to assemble this code that somewhat works. The problem is that it’s not working the way I want it to. The code does change the numbers when I press a button but it only changes int and agi and doesnt change str at all, and I want the stats that were randomly generated to equal to 35 and so far it only only changes to either 5 or 6. I’ve already tried adjusting the values myself, but when I messed with the Random.range, it just crashed my program.

The Random.Range is written incorrectly for your script. The Range in this situation would be 1 and 4.
The variables are declared in the wrong spot. They should be outside of the function’s scope entirely (not to mention outside of the for loop).

From the docs;

public static int Range(int min, int max);

Description

Returns a random integer number between min [inclusive] and max [exclusive] (Read Only).

So you want Random.Range(1, 4);

You really should read the manual :stuck_out_tongue:

Thanks guys for the help, but that just leaves me with one more problem, I want the values to equal to 35 and the values just keep increasing every time I press the button.

@Enderkill9 , you should really look over some tutorials on scripting.

Reset your variables down to 5 at the beginning of the function. Just think about it :slight_smile:
They should be adding up to 35 for each call/activation. (already).