- Home /
How to make a button to change the object texture?
Hi,
I'm trying to create a button or an input key which allow me to switch between 2 texture for the same object.One is suppose to be the default gray shader, the other is a jpg texture.
I've tried this but it juste make my object dissapeard:
function Update (){
if (Input.GetKeyDown(KeyCode.Space)){
renderer.enable=!renderer.enabled;
}
}
Can someone help me please? thanks in advance
Answer by gregzo · Oct 17, 2012 at 08:35 PM
http://docs.unity3d.com/Documentation/ScriptReference/Material-mainTexture.html
Your code is just switching the renderer on and off. Try changing it's texture instead.
If I translate your code in pseudo Code, it says :
"set the renderer's enabled property to the opposite of the renderer's enabled property" ( I guess you misspelled enabled, forgetting a d).
Your answer
Follow this Question
Related Questions
Cutout Material is not showing texture transparency? 0 Answers
2 materials/shaders 1 texture? 2 Answers
How can I add another "layer" to my shader? 1 Answer
Cheapest Way to Render Texture on Quad 0 Answers
Multiple texture on material? 0 Answers