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
0
Question by bhuszi · Nov 16, 2010 at 08:27 AM · gui

drawing a box with GUI

function OnGUI() {

print(""+boxselecting);

if(boxselecting){

 var width : int = leftupbox.x - rightdownbox.x;

 var height : int = (Screen.height - leftupbox.y) - (Screen.height - rightdownbox.y);

 var rect : Rect = Rect(rightdownbox.x, Screen.height - rightdownbox.y, width, height);

 //GUI.Box(rect, "Its ALIVE");

 GUI.Box(Rect(rightdownbox.x, Screen.height - rightdownbox.y, width, height), "Its ALIVE");

 //GUI.DrawTexture(rect, selectionTexture, ScaleMode.StretchToFill, true, 10.0f);

 print("GUI");

} }

this is my code for drawing a box and unity gives me the GUI can only be called in OnGUI error whats wrong with my code?

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by denewbie · Nov 16, 2010 at 10:43 AM

I don't know how well you pasted this piece of code but your "function OnGUI()" is missing the "f".

If thats the same as in your code that thats prob the problem?

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 bhuszi · Nov 18, 2010 at 11:48 AM 0
Share

do you mean the f from function because thats there :)

avatar image denewbie · Nov 18, 2010 at 12:23 PM 0
Share

Ok i ll check it out for you then but do oyu have any errors?

avatar image denewbie · Nov 18, 2010 at 12:26 PM 0
Share

Oh one more thing. The Input values for "Rect" should all be float and not int so you might want to check that out.

avatar image
0

Answer by diabloroxx · Nov 16, 2010 at 04:22 PM

You have to Post the entire code to ascertain what is going wrong where. Have you called any other GUI object or referenced any GUI element from any other function. If so, remove that.

Comment
Add comment · Show 2 · 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 bhuszi · Nov 18, 2010 at 11:50 AM 0
Share

private var mouseposition : Vector3; private var boxselecting : boolean = false; private var leftupbox : Vector3; private var rightdownbox : Vector3;

// semi transparent texture for the selection rectangle var selectionTexture;

function Update () { if(Input.Get$$anonymous$$ouseButtonDown(0)){//0 is linker,1 is rechter,2midden mouseposition = Input.mousePosition; if(!boxselecting) leftupbox = mouseposition; boxselecting = true; } if(Input.Get$$anonymous$$ouseButtonUp(0)){ boxselecting = false; mouseposition = Vector3.zero; } if(boxselecting){ rightdownbox = mouseposition; } } function OnGUI() { print(""+b

avatar image diabloroxx · Nov 18, 2010 at 05:49 PM 0
Share

Your code seems to run properly in my system. However, since there is no proper instantiation of the rightdownbox and leftupbox , I don't see any GUI. But I definitely did not get the " GUI can only be called in OnGUI error" . Try disabling this script and see if you have any random code elsewhere in your project. Else, export your package and post it somewhere so that we can check for other errors.

avatar image
0

Answer by Max Kaufmann · May 09, 2011 at 09:24 PM

I found GUI.Box() to be very trap-laden, my solution was to eschew it entirely, and just use GUI.DrawTexture() with a 1x1 colored texture image.

Comment
Add comment · 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

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

GuiTexture (Touch button) unfollow camera! 1 Answer

NGUI: Recommended way of hiding/showing multiple menu panels? 1 Answer

Healthbar is over play dead Animation 1 Answer

in 4.6RC1 uGUI, sprites blocks buttons/scrollrect from clicking/scrolling 2 Answers

cut scence 1 Answer


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