Have I missed something here?
my_material.SetTextureScale(“_TexName”,new Vector2(2f,2f));
doesn’t do anything! I can change the scale all I want and nothing happens. what gives?
Have I missed something here?
my_material.SetTextureScale(“_TexName”,new Vector2(2f,2f));
doesn’t do anything! I can change the scale all I want and nothing happens. what gives?
Do you actually have a property in the shader called “_TexName”? If so, that’s a pretty bad name for a variable. ![]()
Heh, no that’s just an example… But I was wondering whether or not SetTextureScale only worked with the default names like “_MainTex” and “_Bump”.
I made a workaround in the shader code to use a proxy Vector2 property to set the scale.
I’m not sure if there is something to do with the way the shader works that made SetTextureScale not do anything. If you look at the material in the inspector while the game is running, none of the tiling properties change to reflect what is set with SetTextureScale
It works with any texture property defined in your shader. Open up the shader and see what they are. _MainTex is the only one used by every built-in shader.
I’m trying to get something similar to work. I’m having a problem understanding accessing components from instances so I’ve been trying to trigger some texture scaling.
function OnMouseDown(){
var pmat = player.GetComponent(Material);
pmat.SetTextureScale("_MainTex", negX);
}
where negX is a Vector2 = (-1,0). I know there is something simple that I’m doing wrong. I just don’t see it yet.
Material is not a component. (You can see that it inherits directly from Object, not Component, like Renderer does.)
player.renderer.material.mainTextureScale.x = -1;
Or maybe
player.renderer.material.mainTextureScale.x *= -1;
if you just want it to flip every time.
OOOH!
Thank you! That’s exactly what I overlooked. I forgot that vectors can be accessed by xyz! Well. That fixes many of my issues.
Thanks again!