Texture Offset - bump AND main color

I am trying to animate a texture - well, I do animate it but the bump map on the texture stays behind. Here's what I tried (and nothing happens);

float diff = 0.2f;          
if(localVelocity.z < 0)
        cog.material.mainTextureOffset += new Vector2(0.0f, velocity * (1-localVelocity.x*diff));
        cog.renderer.material.SetTextureOffset("_BumpMap", new Vector2(0.0f, velocity * (1+localVelocity.x*diff)));

The documentation is rather sparse on examples, and the code is a tad more complex than I am used to play with (artist - not coder, please understand : )


Assuming you're using one of Unity's built-in shaders, this will mean you have different UV sets for each texture. So it makes sense to do what you did and apply the offset on both.

I'm actually surprised from your code that it works on the main texture because you don't even go through the renderer to reach your material. Have you tried doing the same thing for the bump map, removing .render completely?

One problem, maybe not all of them. Your MainTex line adds velocity, but your BumpMap line says the offset IS the veocity. A speedometer rather than an odometer. You should be seeing the bumpMap wiggle a tiny bit as you change speed. There's no += for secondary textures, but you can do it the long way:

Vector2 bOff = cog.renderer.material.GetTextureOffset("_BumpMap");
bOff.y += velocity * (1-localVelocity.x*diff); // same thing you were adding to mainTex
// throw in a multiplier, above, if the textures aren't scaled the same
cog.renderer.material.SetTextureOffset("_BumpMap", bOff);

I'm not sure, just guessing, maybe your shader uses a different name instead of "_BumpMap". If so, then you need to open up your shader and check the name.