- Home /
Question by
NuclearBunnies · Nov 21, 2014 at 05:29 PM ·
texturematerialcombinemeshes
Attaching scripts to meshes with multiple materials
I am trying to attach a texture offset script to a combined object with multiple textures. How can I attach the script so that each texture can have their own input values for this script?
Comment
Answer by Pawscal · Nov 21, 2014 at 05:48 PM
you can refer to a specific material by using Renderer.Materials[index]
Materials with an "S"
http://docs.unity3d.com/ScriptReference/Renderer-materials.html
Answer by psycocrusher · Nov 21, 2014 at 06:35 PM
Try somthing like this:
private var scrollSpeed : float = 0.05;
function Update () {
var offset : float = Time.time * scrollSpeed;
//Change material number and name for your own
if(renderer.materials[0].name == "Water_Mat (Instance)"){
renderer.materials[0].SetTextureOffset ("_MainTex", Vector2(-offset,0));
renderer.materials[0].SetTextureOffset ("_BumpMap", Vector2(-offset,0));
}
}
}