Tanuki Digital Forum
UNITY => MISC. Products and Discussion => Topic started 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
-
nvmd think i got how from autodilate
-
Glad you got it working :) Let me know if you run into any further trouble.
-
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.
-
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
-
Also, I split these questions into their own new topic, in case others reading this board have similar issues :)
-
Oh thanks so much, man. That was a perfectly thorough answer.