trying to work out how to change either texture on material or material on shader with spacebar, not sure if either way is easier than the other if anyone can help with the shortest script, i know i need to access the material or shader somehow just getting in a muddle with the getcomponent command cant seem to access the right bit
Materials are not Components.
Materials are assets, specifically an instance of a Shader plus optional extra data.
Renderers are Components, so GetComponent() works to get that.
Renderers have a primary .material and an array of all .materials
Steps to success:
-
identify what Renderer you want to access
-
get a reference to that Renderer
-
amend or replace the Material(s) when you want
Here’s more reading:
Materials materials array of materials renderer:
so am i right in saying i should make a material of each texture i have in the set and then change the material with script not the texture?
You can do that, or you can simply have a single material and change the texture field.
thank you