Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Joe 23 · May 12, 2011 at 03:56 PM · guidialoguepoint-and-click

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?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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?

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Joe 23 · May 12, 2011 at 06:52 PM 0
Share

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?

avatar image Joe 23 · May 12, 2011 at 07:14 PM 0
Share

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:

http://pastebin.com/d$$anonymous$$fJqc7X

avatar image Bampf · May 13, 2011 at 04:39 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges