Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

problem with the new text system

Discussion in 'UGUI & TextMesh Pro' started by kondor, Jun 25, 2015.

  1. kondor

    kondor

    Joined:
    Jun 18, 2013
    Posts:
    48
    HI
    Im new with this system,I wrote this code:
    Code (CSharp):
    1. float val = Input.GetAxis ("Mouse ScrollWheel")*sense;
    2.         if (val == 2)
    3.         {
    4.             i++;
    5.             labels[i].material.color = Color.red;
    6.         }
    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?
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,850
    Sounds like they are all sharing the same material. Try creating a new material for the label

    Code (csharp):
    1. labels[i].material = new Material(labels[i].material);
    2. labels[i].material.color=Color.red;
     
  3. kondor

    kondor

    Joined:
    Jun 18, 2013
    Posts:
    48
    yea it share the same material thx for the help
     
  4. Pharan

    Pharan

    Joined:
    Oct 28, 2013
    Posts:
    102
    what type is the labels array made of?
     
  5. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,488
    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.
     
    karl_jones likes this.