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 pigi5 · Jan 25, 2011 at 06:21 AM · cameracenteralignment

Gui.drawtexture using center instead of corner for positioning

is there a way to use the center to align the Gui texture instead of the top left as is the standard. I am trying to draw Gui textures using GUI.DrawTexture, but using the top right to draw the location is really confusing to me. I have a minimap in the top right corner of my screen, and I am trying to use that width and height to base my Gui textures off of, but the locations are wack. It might be because my camera width and height variables are wrong, but I can't tell. Here is one of my textures that is not drawing in the desired location (this one was supposed to draw in the center of the camera):

GUI.DrawTexture(Rect(Screen.width-(camera3Width*0.5)-(mapMarkerRect*0.5),
                    (camera3Height*0.5)+(mapMarkerRect*0.5),
                    mapMarkerRect,mapMarkerRect),mapMarker);

My camera height and width variables were originally using this script:

camera3Width = Screen.width*0.21;
camera3Height = Screen.height*0.4;

I was using this because the numbers I am multiplying the screen size by were the normalized viewport rect height and width numbers of the camera (minimap). Is there a different way to find the camera size in pixels or center the Gui Textures?

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
Best Answer

Answer by Jesse Anders · Jan 25, 2011 at 06:59 AM

I don't know that the GUI system provides any built-in support for what you describe. However, you could easily write a wrapper function to hide the details, so that you don't have to do all the math manually each time.

Comment
Add comment · Show 5 · 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 pigi5 · Jan 25, 2011 at 12:54 PM 0
Share

I don't even know if my math is right though.

avatar image Jesse Anders · Jan 25, 2011 at 01:25 PM 0
Share

You should be able simply to offset the rect origin by half the width and height of the rect; that's what I've always done for 'centered' GUI controls. Unless there's more to the problem, that is (it looks like there might be, based on what you posted, but I'm not clear enough on the nature of the problem to comment further).

avatar image pigi5 · Jan 25, 2011 at 10:48 PM 0
Share

Yes, I asked whether there was a way to find the camera ($$anonymous$$imap) width and height in pixels, possibly using it's screen width and height which are .21 and .4, respectively. I tryed to multiply this by the width and height of the screen, but that didn't work, it ended up almost half the width and height of what it appeared to be.

avatar image pigi5 · Jan 25, 2011 at 11:28 PM 0
Share

I think I have done it right now, yet they are still appearing in the wrong spots when I maximize the game, but when it is $$anonymous$$imized, they are in the right locations, but the wrong sizes.

avatar image pigi5 · Jan 25, 2011 at 11:50 PM 0
Share

haha I figured it out, I had to set the camera height and stuff using the screen hieght in the OnGUI function ins$$anonymous$$d of Start (), which only set them at the beginning ins$$anonymous$$d of after it had maximized, because OnGUI goes every frame.

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

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

How to Get My Camera to Follow First Person POV in First Person Controller 1 Answer

Move camera with mouse (2D) 1 Answer

Problem with Camera Transition (First-person to third-person, with Slerp) 1 Answer

Camera Noise Effect Causing Black Screen? 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