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. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Access Particular Shader Texture through code

Discussion in 'General Graphics' started by dyuldashev, Jun 11, 2018.

  1. dyuldashev

    dyuldashev

    Joined:
    Mar 3, 2016
    Posts:
    74
    I am trying to access a shader texture from code, particularly Texture Sample 1 from the attached image. This is a simple code for accessing/setting shader textures:
    GetComponent<Renderer> ().material.SetTexture ("_MainTex", RenderCamera.targetTexture);

    I was wondering how I can do the same for Texture Sample 1. And the shader is named as ColoringCharacter. Thanks.
     

    Attached Files:

  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,230
    It's impossible to know from the screenshot. You'd need to look a the shader source and see which property has the descriptive text of "Texture Sample 1". If you open up the shader you should see a Properties block with _MainTex ("Sprite Texture", 2D) = "white" {} or something similar. Directly below that will likely be the "Texture Sample 1", look at the variable name to the left (like where _MainTex is) to know what to set from script.
     
    dyuldashev likes this.
  3. dyuldashev

    dyuldashev

    Joined:
    Mar 3, 2016
    Posts:
    74
    Thanks a lot. I was able to find the shader property with the description.