Search Unity

Resolved Change a "shader" texture with code

Discussion in 'Scripting' started by merfolkjh, Dec 29, 2021.

  1. merfolkjh

    merfolkjh

    Joined:
    Sep 18, 2021
    Posts:
    20
    Hi everyone,

    i am 'learning' Unity, sorry for this beginner question, but thanks in advance for any help :)

    I want to test a basic "texture splatting" on a simple plan.
    - Editor : OK
    - In Code : No

    My project :
    im1.png

    The shader has 2 Texture2D properties, that i d like to change
    img2.png

    Here the basic code that should replace the first grass texture by a snow texture, but it does nothing.
    (script is binded to plan object)

    im3.png

    Texture is loaded, no error, but no change on screen.
    What am i doing wrong ?

    Thanks !
     
    Last edited: Dec 29, 2021
  2. merfolkjh

    merfolkjh

    Joined:
    Sep 18, 2021
    Posts:
    20
    Pb solved, it works but you must use the REFERENCE and not the NAME

    ```
    GetComponent<Renderer>().material.SetTexture("Texture2D_e45a0dfb99f446d1a43b69f1558a1f87",myGUITexture);
    ```