Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 vverma9 · Feb 19, 2019 at 10:36 PM · screenhud

Unity3D: Display the game only on 90% of the screen space

Currently my game occupies 100% of the screen, and HUD elements are scattered around the corners. Some of top-right, some on bottom-left, and some on bottom-right. Is there a way using which I can push the HUD elements to occupy right 10%(say) part of the screen, and remaining 90% left part be used to render the game? Something like the example below?

I could move the HUD to the right part, but then it will hide the game screen below it. Is there any way, I could reserve the right part for HUD only?

alt text

Comment
Add comment · Show 13
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 zereda-games · Feb 19, 2019 at 10:44 PM 0
Share

I think this is what you might be talking about le'me know.

https://docs.unity3d.com/ScriptReference/Camera.ScreenToViewportPoint.html

avatar image vverma9 zereda-games · Feb 19, 2019 at 10:56 PM 0
Share

Yes, it looks like. I want the game to occupy left 90% of viewport, and HUD to occupy the right 10%.

avatar image zereda-games vverma9 · Feb 19, 2019 at 10:57 PM 0
Share

this should do what you want then if you are not too sure about it search up "Camera.ScreenToViewportPoint - unity"

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Ymrasu · Feb 27, 2019 at 03:44 AM

Actually, cameras have a rect struct on them to determine the portion of the viewport to render on. Measured from 0f to 1f (percentages). So you can do something like this:

 Rect camRect = Camera.main.rect;
 camRect.xMax = 0.9f; // 90% of viewport
 Camera.main.rect = camRect;

Doing this though means that you need a second camera set up to only look at your UI with the xMin starting at 0.9f

Comment
Add comment · Show 1 · 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 vverma9 · Feb 27, 2019 at 03:48 AM 0
Share

wow, that's a much better and elegant solution. $$anonymous$$uch thanks to you :)

avatar image
3

Answer by AaronBacon · Feb 27, 2019 at 12:04 AM

So, this may not be the Best way to do it, but you can render a Camera to a UI Object on a canvas, similar to a Minimap, Instead of just filling the players view with it. To do this, you need to make a new camera, as well as an object in your assets folder called the Render Texture, that will allow the new Camera to cast to it. alt text

You then want to go into the new Cameras Inspector and Set that Render Texture asset to be its Target Texture alt text

Finally, you want to create a UI "RawImage" Element in the scene. You can then set its Texture To also be the Minimap Render Texture. What You should now have is a scene that has a Texture on the canvas Showing the Camera View of the Minimap Cam. Eg: alt text

Now you should be able to just mess with the Camera, Render Texture and RawImage Settings to get it to cover a sufficient area of the screen. (Probably set the Canvas to Scale with screen Size)

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 vverma9 · Feb 27, 2019 at 01:26 AM 0
Share

Thanks for your insight, I will try it and get back to you.

avatar image shieldgenerator7 · Nov 20, 2020 at 02:59 AM 1
Share

This was exactly what I was looking for. Thank you!

avatar image AaronBacon shieldgenerator7 · Nov 26, 2020 at 04:08 AM 0
Share

No Problem, glad I could help lol

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

104 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I scale a GUITexture from the sides instead of in the center? 1 Answer

Render Sprite on Screen at 3d game 0 Answers

Make my HUD full screen 2 Answers

How do I get my Ammo Hud on the bottom right of the screen? 1 Answer

Positioning according to aspect ratio 4 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