problem with the new text system

HI
Im new with this system,I wrote this code:

float val = Input.GetAxis ("Mouse ScrollWheel")*sense;
        if (val == 2)
        {
            i++;
            labels[i].material.color = Color.red;
        }

the problem is that I have 4 texts,the value of i is 0,when I role the scroll wheel all the text become red not just the text in the i position in the array,its painting all the texts under the same canvas and not seperatly
how can I solve it?

Sounds like they are all sharing the same material. Try creating a new material for the label

labels[i].material = new Material(labels[i].material);
labels[i].material.color=Color.red;

yea it share the same material thx for the help

what type is the labels array made of?

The UI.Text component has its own color field for each instance, even if they share the same material. That way you don’t need to make multiple material instances and Unity can still batch your labels together.

1 Like