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
2
Question by Tobias · Jun 15, 2010 at 07:32 PM · positionrectangle

Mysterious Rect problem

Hello. I have a crazy problem with Rect().

When I use

GUILayout.Window(0, Rect(Screen.width/2-75,Screen.height/2-75, 150, 100) , LoginWindow, "Loginversuch");

The window is in the center of the screen.

But when I define a variable with the same rect

private var windowRect = Rect(Screen.width/2-75,Screen.height/2-75, 150, 100);
GUILayout.Window(0, windowRect , LoginWindow, "Loginversuch");

Then only the width is centered but not the height (its over the top of the screen).

I cant find the problem. Please help, thanks again for your great help :)

EDIT. When I use (Debug.Log(windowRect) I get

(left:551,00, top:344,00, width:150,00, height:100,00)

Which seems to be fine, but why it doesnt apply the correct top value?

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
2

Answer by Ezzerland · Jun 15, 2010 at 08:52 PM

Try:

var windowRect : Rect = Rect((Screen.width/2)-75, (Screen.height/2)-50, 150, 100);
windowRect = GUILayout.Window(0, windowRect, LoginWindow, "Loginversuch");

In this case, I only added a space before Screen.height, parenth, and followed the basic unity example of a window found here: http://unity3d.com/support/documentation/Components/gui-Controls.html

also removed a space after 0, windowRect ,

Also, to be a bit more precise in center from top, it should be half your rect's height. so it should be Screen.height/2-50 I did this above, and also (not that its necessary) added in the additional parenth to find scrn height/width.

Give it a shot, lemme know :)

Comment
Add comment · Show 6 · 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 Tobias · Jun 15, 2010 at 08:59 PM 0
Share

Thank but the space doesn't fix the problem.=(

Also thanks for my little mistake with 75 ins$$anonymous$$d of 50.

Any other idea how to fix the problem?

avatar image Ezzerland · Jun 15, 2010 at 09:10 PM 0
Share

Oh, yes. The second line should be:

windowRect = GUILayout.Window(0, windowRect , LoginWindow, "Loginversuch");

avatar image Tobias · Jun 15, 2010 at 09:13 PM 0
Share

Also tried this (Copied from example).. doesnt work =/ Thanks anyway

avatar image Ezzerland · Jun 15, 2010 at 09:37 PM 0
Share

Edited the original answer post for a fuller example of code. I'm not at home and in turn unable to test the code myself, but I see no reason it really should not work. If the above attempt doesn't work, then without fiddling with it I'll leave you to find someone more knowledgeable in js. I don't really use js myself :p

avatar image Ezzerland · Jun 15, 2010 at 09:40 PM 0
Share

Not that this should matter, but pending where the variable is located, is it necessary to make the variable private? if it's inside a function or etc, it already will be private. This really shouldn't matter, but, just curious of the use.

Show more comments

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

How to fit rectangles to sprites? 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Unity error, can't modify transform.position value 1 Answer

Animation by Scripting point A to B 1 Answer

Vector3 Transform.Position Not Working 2 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