- Home /
Menu material error
Hi,
I have a cube with the button script which I am trying to modify. To show a button and a picture of the texture that I want to be applied.
var btnTexture : Texture;
var bumpMap : Texture;
function OnGUI() {
if (!btnTexture) {
Debug.LogError("Please assign a texture on the inspector");
return;
}
if (GUI.Button(Rect(10,10,50,50),btnTexture))
Debug.Log("Clicked the button with an image");
if (GUI.Button(Rect(10,70,50,30),"Click")){
Debug.Log("Clicked the button with text");
renderer.material.SetTexture("_BumpMap", bumpMap);
}
}
So, when I run it it says that material doesn't have a texture property _BumpMap. Why is that? Do I need to apply something else to the material?
P.S. - post the answers as comments to this post or I will answer them as comments in this post.
Thank you all. Cheers.
Why would someone post the answer as a comment as opposed to, say..an answer?
I can't comment on other people's replies so I'll have to make a new reply or post comments on this post. If I post as a reply I'll get downvoted just like a got the last time.
You can comment on other people's replies, and that's actually the way you should do it. The wrong way to do it is to post an answer as a reply. Look at this answer and notice that the answers have their own replies (http://answers.unity3d.com/questions/13784/players-projectile-communicating-with-enemy.html) You get down voted when you post a new answer for every comment you have.
Try commenting now. The permissions were changed quite recently because of that problem.
Answer by Waz · Jul 29, 2011 at 10:54 PM
Ensure the Material on the Renderer is a Bumped one.
It's set as a default diffuse, so what I want to do is when I click the button a texture is applied to the cube.
The you also need to set the shader:
renderer.material.shader = Shader.Find("Bumped Diffuse");
(note that it is better to use a variable for that Shader as you have for the other attributes, since it performs better and ensures correct dependencies, I just used the simplest to write and understand)
Put it into the script still not working.
Here is how it's set up : Cube's mesh renderer is - Default Diffuse. I've made a material that I've named _Bump$$anonymous$$ap which is bumped specular but don't use it. I have a texture that I also named _Bump$$anonymous$$ap which I attached to the script. And that's it. Error : material doesn't have a texture property _Bump$$anonymous$$ap.
Your answer
Follow this Question
Related Questions
Modifying scroll texture 1 Answer
Repositioning remote GUI Texture 1 Answer
GUI Info button not displaying 1 Answer
How can i show the texture in the array? 2 Answers
DrawTexture GUI iPhone 1 Answer