ScoreBoard Counter Problems

I’m racking my brains at this and I am guessing I am over looking the simple solution. Searching for answers and haven’t found one that works with what i am trying to do.

I have a score counter, it is using UI.Images for each number. Tried different methods which all turned into errors for me.

I have a Index of 0-9 sprites, and 6 “sections” that need to change.

183339-score.png

Basically, if the score is 980345, it needs to display from 0 to 5 in the sections.

183340-scorep.png

scoreUIImage0.sprite = ui_Numbers[playerman.playerScore % 10];

Using that script will make the “0” slot work. But breaks for the rest of the slots. I am probably not using it correctly

var str = playerman.playerScore.ToString()
var len = str.Length;
var int0 = Int32.Parse(str[len - 1].ToString());
scoreUIImage0.sprite = ui_Numbers[int0];

You can apply similar approaches for the rest of the sprites. You are taking mod base 10 so its only working for the last digit. If you wanna go with the math approach you need the divide that playerScore by 10 at each step. Like this you can use the lastDigit as your indexing variable:

var tempInt = 1234;
while (tempInt != 0)
{
    int lastDigit = tempInt % 10;
    tempInt = tempInt / 10;
}