Search Unity

Find all texture on children of GameObject and change them to other.

Discussion in 'Scripting' started by Slyrfecso1, Aug 24, 2015.

  1. Slyrfecso1

    Slyrfecso1

    Joined:
    Jul 16, 2012
    Posts:
    100
    Hi,

    Modified post:
    The code is changing all texture on tagged layer. Unfortunately I need to add one by one Children of GameObject to tagged layer.

    I'd like to find all textures on an Objects and changing to other without modifying other materials. Maybe the gameobject can stay on tagged layer.

    Any idea will be helpful.


    Code (CSharp):
    1.  
    2. public Texture[] texturesButorlap;  //Important to add same textures in Inspector window
    3.  
    4. foreach(GameObject termek in GameObject.FindGameObjectsWithTag("Butorlap Objects List"))
    5. {
    6. Renderer[] rendererComponents = termek.GetComponentsInChildren<Renderer>();
    7. foreach (Renderer component in rendererComponents)
    8. {
    9. int index = inventory[i].butorlapID;
    10. component.GetComponent<Renderer>().material.mainTexture = texturesButorlap[index];
    11. }
    12. }
    13.                             }
     
    Last edited: Aug 25, 2015