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 tomixx · Nov 21, 2012 at 01:22 AM · guiuser interfacehudminimapresolutions

How do you get a minimap to stay rooted to the top left corner of the screen despite resolution changes?

I am making a TBS game and am currently working on the HUD, I have tried different code types and all were unsuccessful.

For example part of the HUD is the minimap that i want to root to the top left corner of the screen, it works for one resolution but when i switch to a different one it appears in a different location.

I have looked through the forums and either the answer doesn't work or the question is not answered.

What is the best way to fix it?

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
1

Answer by sparkzbarca · Nov 21, 2012 at 04:52 AM

use

http://docs.unity3d.com/Documentation/ScriptReference/Camera.ViewportToWorldPoint.html

the top left of the screen is Camera.main.ViewportToWorldPoint(new vector3(0,1,0));

the top left of the screen and 2 meters forward is

Camera.main.ViewportToWorldPoint(new vector3(0,1,2));

the center of the screen is half way along the x axis and half way along the y axis or just FYI an 'f' after a number makes it a float in case you were unaware.

Camera.main.ViewportToWorldPoint(new vector3(.5f,.5f,0));

hopefully that answers your question.

Viewport functions are independant of the resolution.

(0,0) is the bottom left and (1,1) is the top right regardless of resolution.

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 tomixx · Nov 27, 2012 at 11:10 PM 0
Share

I can see how this would work but I do not know how to attach the texture to it, is this possible?

avatar image Giantbean · Jan 30, 2014 at 09:46 PM 0
Share

Can someone please clarify this answer?

If I have a $$anonymous$$ain Camera and I place a $$anonymous$$ini-$$anonymous$$ap or a Picture-in-Picture camera that I want anchored in the top left (or right) I set the second cameras view-port Rectangle and then I attach a script like the one in the scripting reference:

 using UnityEngine;
 using System.Collections;
 
 public class Example : $$anonymous$$onoBehaviour {
     void OnDrawGizmosSelected() {
         Vector3 p = camera.ViewportToWorldPoint(new Vector3(1, 1, camera.nearClipPlane));
         Gizmos.color = Color.yellow;
         Gizmos.DrawSphere(p, 0.1F);
     }
 }

using (0,1,camera.nearClipPlane) for left top or (1,1,camera.nearClipPlane) for the top right, I still end up losing the edges of the $$anonymous$$i screen when moving the game window size in free aspect mode.

Any help clarifying this would be greatly appreciated.

avatar image Giantbean · Jan 30, 2014 at 11:15 PM 0
Share

I found THIS was much closer to what I needed.

 using UnityEngine;
 using System.Collections;
  
 public class $$anonymous$$y$$anonymous$$inimapResizer : $$anonymous$$onoBehaviour
 {
 private float itsWidth;
 private float itsHeight;
 private Camera its$$anonymous$$inimapCamera = null;
  
 // Use this for initialization
 void Start ()
 {
 its$$anonymous$$inimapCamera = GetComponent();
 }
  
 // Update is called once per frame
 void Update ()
 {
 itsHeight = 1.0f/3.0f; //set the $$anonymous$$imap height to 1/3 of the screen
 float itsScreenHeightInPixels = Screen.height*itsHeight;
 float itsScreenWidthInPixels = (itsScreenHeightInPixels/9.0f)*16.0f;
 itsWidth = itsScreenWidthInPixels/Screen.width;
 float anX = (1-itsWidth)/2.0f; //centers the $$anonymous$$imap
 its$$anonymous$$inimapCamera.rect = new Rect(anX,0.0f,itsWidth,itsHeight);
  
 }
 }

avatar image
0

Answer by kolmich · Nov 26, 2012 at 10:45 PM

Hi,

Check out the KGFMapSystem, [http://forum.unity3d.com/threads/147121-Minimap-Map-System-RELEASED][1] [1]: http://forum.unity3d.com/threads/147121-Minimap-Map-System-RELEASED

We have already solved tons of other minimap problems here (4 month of developement + bugfixing + content creation). This unity3d minimap works out of the box, is fully customizeable and if you will need an additional feature just make a feature request at kolmich.at/forum.

Michal

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
avatar image
0

Answer by Owen-Reynolds · Jan 30, 2014 at 10:39 PM

The standard solution is to set GUIs/miniMaps/etc... once at the start, and then rerun those calculation whenever the window changes size. Actually, the most common fix is just to never let the user change size -- run only full-screen. Can you even resize iOS/Android apps?

Some systems provide an OnResize() callback, where you can just paste the "setup GUI coords" code. Unity doesn't have that (I assume since not all platforms support it?) So you have to check "did the screen size change" yourself (goggle "Unity resize callback.")

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

13 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

Related Questions

Minimap blib icon error 1 Answer

Problems with Minimap 1 Answer

How to position 3D-GUI-Mesh on change of aspect ratio? 0 Answers

Maintaining Image Aspect Ratios in GUI using Matrix? 1 Answer

Multi Camera HUD buttons not working. 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