- Home /
More simple code not working
What's up here? I have a button that I press to show/hide a info object. It works the first time I press but not afterwards, I don't see the problem:
var currenttexture : Texture2D; var newtexture : Texture2D; var self : GameObject; var myCheck : boolean = true; var info : GameObject;
function OnMouseEnter () { self.renderer.Material.maintexture = newtexture;
}
function OnMouseExit () { self.renderer.Material.maintexture = currenttexture;
}
function OnMouseDown () {
if(myCheck){ info.guiText.enabled = true; mycheck = false; }else{ info.guiText.enabled = false; mycheck = true; } } Also the first part is supposed to change the button appearance but not working either. Thanks for any help!
@Draspur Can you format the code please. Edit post, select all the code, cntl/cmd k or use the 101 010 button in the tools bar above the post.
It looks like your copied your code in here twice. Is that the case? Also, see the comment below.
Your post (as it appears now) probably isn't appropriate for UnityAnswers. The UnityAnswers philosophy is:
"[Unity Answers] is a place to ask specific questions that have specific answers. The forum is a better place to post discussions and non-technical questions."
As a general rule, posts should probably have the following:
A clear question (what, specifically, are you trying to do?)
Relevant background information (what have you already tried? what other things might be important for us to know?)
Context information (what do you expect to happen? What is happening ins$$anonymous$$d?)
Your request (what specifically do you expect of the UnityAnswers community? Are you looking for links to relevant information, a chunk of code that you can use, ...?)
If your post is one of the following, you should consider changing it or asking on the forums ins$$anonymous$$d:
A one- or couple-sentence post, especially with a broad question ("how do I make a game like Halo?") or no discernible question ("WebPlayer doesn't allow me to save to disk"). We'll need more specific information to help you.
Asking the opinion of the community ("Best method to store files?"). $$anonymous$$uch better to discuss these on the forums.
A question that focuses on the end result, rather than anything technical ("how do I make a laser beam?"). These mean that you probably haven't done enough research. If you're just starting out and don't even know where to look, try searching here, the forums, and Google first and then posting your question to the forums. The Unity resources are a great place to start (http://unity3d.com/support/resources/). When you get to a more technical point ("how do I adjust the color of a line renderer for a laser beam?") we can probably help you.
A disjointed or incomplete question ("How do I make a jumping enemy? Physics doesn't look right."). It will help us if you take a moment to add some context information, background, and general explanation.
Copying your code verbatim with a one-line question like "why doesn't this work?" or "what is wrong with my code?" To the community, this sounds like you came across an error, spent 0 time trying to fix it yourself, and simply posted it in the hope that someone else would do your work for you.
Finally, make sure that you check to see if your question has already been answered here, and do a quick google search, before posting a new question.
Of course, the members here are awesome folks and will probably try to help you anyway - hopefully you'll get an answer or some helpful comments. If not, now you know why.
Answer by aldonaletto · Apr 26, 2012 at 12:07 AM
I would use a simpler way to toggle the boolean variable - maybe using the guiText.enabled property directly. About the material: you're writing Material, but it's material. Try this version:
var currenttexture : Texture2D; var newtexture : Texture2D; var self : GameObject; var info : GameObject;
function OnMouseEnter (){ // its material, not Material: self.renderer.material.maintexture = newtexture;
}
function OnMouseExit (){ self.renderer.material.maintexture = currenttexture;
}
function OnMouseDown () { // toggle guiText.enabled: info.guiText.enabled = !info.guiText.enabled; }
Your answer
Follow this Question
Related Questions
Assigning UV Map to model at runtime 0 Answers
Why doesn't my script work? 1 Answer
Rect, Texture, GUI, Detection. 1 Answer
Object Texture Showing Blur In Game 1 Answer
Clear previous GUI.DrawTexture 0 Answers