I may be missing something fundamentally obvious here, but looking elsewhere for solutions has yielded no results, so I thought I’d ask in case someone can enlighten me…
I have a small array of integers created
countTypes = new int[]{0,0,0,0,0,0};
and the value for each index is calculated by counting the number of certain objects in a scene. The counting seems to work fine & stores the correct values, however I’m running into issues subtracting from the stored values and I’m not entirely certain just why.
I’m using a Random.Range to randomly pick one of the stored indexes, and then wish to subtract 1 from the number found there:
rnd = Random.Range(0,countTypes.Length);
countTypes[rnd] = countTypes[rnd] - 1;
Unfortunately, the subtraction line almost always causes the editor to crash. If I comment out that single line, the rest of my code functions without a hitch, so I’m left to assume that I’ve made a mistake in how I’m approaching the math. It seemed simple and straightforward enough, or so I thought, but for whatever reason it simply doesn’t function.
I’ve been trying to debug this for a few days now, believe I have finally narrowed the issue down to this one line of code, cannot understand why it isn’t working properly, and would most certainly appreciate any assistance any of you might have to offer.