Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Сhanging texture element model

Discussion in 'Scripting' started by Wolchau, Oct 1, 2016.

  1. Wolchau

    Wolchau

    Joined:
    Oct 1, 2016
    Posts:
    2
    How can I change the texture of one of the elements of the model?

    Before that, I used the model with one element in the material, the script was:
    newObj.GetComponent<Renderer>().material = newMaterial;

    Now I have a model with several elements:
    upload_2016-10-1_19-43-39.png

    How do I convert script to change one of the elements of the material?
    I apologize in advance for the stupid question.
     

    Attached Files:

  2. unitynoob24

    unitynoob24

    Joined:
    Dec 27, 2014
    Posts:
    398
    Not sure as I have never done this.. but since they are in an array.. possibly something like this?

    Code (csharp):
    1.  
    2.  
    3. newObj.GetComponent<Renderer>().materials[0] = newMaterial;
    4.  
    5.  
    0 in this case being your FrontColor material.
     
  3. Wolchau

    Wolchau

    Joined:
    Oct 1, 2016
    Posts:
    2
    it did not work, the material does not change.

    I tried to use <MeshRenderer> instead <Renderer>. The result is the same
     
    Last edited: Oct 1, 2016