Tanuki Digital Forum

UNITY => MISC. Products and Discussion => Topic started by: finn on July 11, 2016, 09:15:19 AM

Title: EyeAdvanced Help
Post by: finn on July 11, 2016, 09:15:19 AM
Hey is there any way to access and change the material attributes of EyeAdvanced (iris color, limbal ring amount, etc.) with scripts?

Great Product and Thank you
Title: Re: EyeAdvanced Help
Post by: finn on July 11, 2016, 09:57:21 AM
nvmd think i got how from autodilate
Title: Re: EyeAdvanced Help
Post by: Chingwa on July 11, 2016, 07:04:19 PM
Glad you got it working :)  Let me know if you run into any further trouble.
Title: Re: EyeAdvanced Help
Post by: finn on July 12, 2016, 08:01:52 AM
public class SetRandomIris : MonoBehaviour {
    Renderer lre;
    Renderer rre;
    public Texture[] Textures = new Texture[60];
    // Use this for initialization
    void Start () {
        Renderer lre= GameObject.Find("LeftEye").GetComponent<Renderer>();
        lre.enabled = true;
        Renderer lrre = GameObject.Find("RightEye").GetComponent<Renderer>();
        rre.enabled = true;
       
        int tran = Random.Range(18, 29 );
        int gran = Random.Range(180, 255);
        int rran = Random.Range(180, 255);
        int bran = Random.Range(180, 255);
        Color crandom = new Color(rran, gran, bran);
        lre.sharedMaterial.SetColor("_irisColor",crandom);
        rre.sharedMaterial.SetColor("_irisColor", crandom);
        lre.sharedMaterial.SetTexture(tran, Textures[tran]);

The texture change aspect doesn't actually seem to be working, could you possibly tell me what is wrong with my code? I imagine it's in the Set call.
Title: Re: EyeAdvanced Help
Post by: Chingwa on July 12, 2016, 10:14:59 AM
Your set texture call isn't accessing a texture name on the shader.  you need to give it the name of the texture you want to set in the first attribute.  So instead of this...
lre.sharedMaterial.SetTexture(tran, Textures[tran]);

you should use this...
lre.sharedMaterial.SetTexture("_IrisColorTex", Textures[tran]);

This is a list of the different texture names used in the shader.  the "_IrisColorTex" is the most common texture to be changed, unless you're doing something very specific.
_IrisColorTex
_IrisTex
_CorneaBump
_EyeBump
_IrisBump
_MainTex
Title: Re: EyeAdvanced Help
Post by: Chingwa on July 12, 2016, 10:18:09 AM
Also, I split these questions into their own new topic, in case others reading this board have similar issues :)
Title: Re: EyeAdvanced Help
Post by: finn on July 13, 2016, 02:37:54 AM
Oh thanks so much, man. That was a perfectly thorough answer.