- Home /
GUI menu problems
Hi guys,
I can't figure out where I'm going wrong. The idea of this code is that it will be used with a collider on an NPC. When it's clicked with the mouse a GUI will pop up enabling the user to "ask questions".
I've tried this many different was and I can't seem to figure it out, which is really frustrting. I decided in the end it would be easier to write it like this:
private var isClicked : boolean = false; var dialogueGUI : Texture2D; var newSkin : GUISkin;
function dialogueMenu() {
GUI.DrawTexture(Rect (0,0,700,450), dialogueGUI, ScaleMode.ScaleToFit, true, 1.0f); } function OnGUI() {
GUI.skin = newSkin;
if(!isClicked) return;
dialogueMenu();
print ("dialogue GUI is displayed"); }
function OnMouseUp() { isClicked = true; }
As you can see, OnGui - when the mouse is clicked - calls dialogueMenu() which will hold all the GUI data. But I'm getting this error:
ArgumentException: You are not allowed to call get_guiTexture when declaring a variable. Move it to the line after without a variable declaration. Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function. dialogueScript..ctor () (at Assets/Scripts/dialogueScript.js:2)
Anyone know why?
Answer by Bampf · May 12, 2011 at 05:34 PM
Your script works for me in Unity 3.2. (The click behavior is a little strange in my test scene, but I haven't investigated and that's not what you were asking about.)
FYI I googled your error and I didn't find other people having the same problem. Too bad, because that might have given us a clue.
Try assigning the default GUISkin, and a standard asset texture, just to make sure the problem isn't in those objects.
Is the script above the exact same as the script you are trying to compile? Try creating a new empty script and pasting the above text directly into it (which is what I did.) Just in case there's some weird corruption in the file, or hidden characters.
Are you sure this file is the one generating the error? If you cut most or all of the text out of it, does the error go away?
Hey, thanks for the reply. I've sorted the problem now. I gave up trying to use the custom skin and just coded out a simple GUI with the same dimensions, so when I find out how to use my own image I can just swap them.
I do have another question though: how can I get the screen to lock when the GUI comes up? So the mouse doesn't move the camera?
Also, I'm having trouble getting the Text Area to reset. I have a default string value that I want the text area to display, which it doesn't seem to want to do. It's weird, I set responseString up with one previously, but then decided to change it, but the program still displays the old value in the text area. And when I hit the exit button, and then go back into the conversation - the last response is still in the dialogue box...?
Here's a link to the new code:
Understand, this isn't a forum so each question should get posted separately. Having said that, some hints: 1) $$anonymous$$ouse doesn't move camera automatically. You are using a script (like $$anonymous$$ouseLook, or your own custom code) to do it. You may have to add a boolean to toggle that behavior on and off. 2) responseString is public, visible in the Unity editor. Once object is instantiated in the scene the initializer setting it to "NO ENTRY" won't run again. Try initializing it in Start() or OnLevelWasLoaded() ins$$anonymous$$d, or clear it whenever the dialog is about to be shown.
Your answer
Follow this Question
Related Questions
DIY Dialog System (type-writer effect) 1 Answer
Creating a dialogue with Physics.OverlapSphere 0 Answers
Problems with simple dialogue 0 Answers
GUI Pop-Up On Cube Collision 1 Answer
Strange NullReferenceException when drawing DragableWindow 0 Answers