Solution
For whatever reason the texture/material for my object was stored in the armature hierarchy (“orbSwitch > orb_armature > pedestal”) so when I applied the script to change it to that part of the object (“pedestal”) it began to work. I figured that having a texture in the parent (“orb switch”) would over-ride the texture/material underneath it, but that is apparently an incorrect assumption. So my script just wasn’t being specific enough to find where the active texture was in order to change it.
Previous Problem
I have a switch that I would like to change textures on when it is hit by the player. You can see it in the image. On the right is the inactive, yellow, switch and on the left is the active, green, switch. Both switches are exactly the same, except for their textures and the fact that the green one is animated to spin when hit.
So far I’ve tried changing it via materials and via textures and neither seems to update the texture. When I hit play it stays the original yellow texture. Since I figured the animation and trigger testing might be complicating things I went to a test scene and started messing around with only the non-animating switch to see if I could even change its texture via a script.
I added in two variables which are linked to the two texture files through the inspector (both textures are the same except for the color of the top part of the texture). Then I tried using the mainTexture command as suggested for changing textures in the first example from the script reference page. This results in no change.
I’ve also tried using “renderer.material.SetTexture(”_MainTex", textureOn);" with no results.
There was also an example somewhere using an array to cycle through materials and I couldn’t get it to work which is why I have multiple materials set on the object as you can see in the bottom right of the image.
So in summary, how do I get it to change materials or textures if the commands listed in the scripting reference don’t seem to do anything when I hit play?