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 bpears · Sep 05, 2012 at 03:17 AM · c#guiminimap

How to make minimap GUI stay put?

I am using C# scipt to use render texture and material. When I switch from 16:9 screen ratio to full screen on play, the GUI is in another location. How can I make it stay?

Would it be in the right place if I built the game in 16:9 and resized my screen?

Thank you!

note: even when dragging the screen to enlarge the scene view, the GUI gets out of place, while being in 16:9 the entire time.

Here is my script for minimap:

 using UnityEngine;
 
 
 public class minimapcee : MonoBehaviour {
     
     public RenderTexture MiniMapTexture;
     public Material MiniMapMaterial;
     
     private float offset;
     
     void Awake()
     {
         offset = 10;
     }
     
     void OnGUI()
     {
         if(Event.current.type == EventType.Repaint)
             Graphics.DrawTexture(new Rect(14, 278, 88, 88), MiniMapTexture, MiniMapMaterial);
     
     }
 }

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
Wiki

Answer by purplelilgirl · Sep 05, 2012 at 03:45 AM

Try using this script:

public float screenWidth = 960; public float screenHeight = 640; Matrix4x4 tMatrix; void Awake () { RotateDevice(); } void RotateDevice() { tMatrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3((float)1.0 Screen.width/screenWidth, (float) 1.0 Screen.height/screenHeight, 1.0f)); } void OnGUI() { GUI.matrix = tMatrix; if(Event.current.type == EventType.Repaint)

Graphics.DrawTexture(new Rect(14, 278, 88, 88), MiniMapTexture, MiniMapMaterial);

}

Set screenWidth and screenHeight to your 16:9 one, and the rest of the script will automatically resize and reposition your GUI based on the current screen size, so that it will always be in the "right" place.

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 purplelilgirl · Sep 05, 2012 at 03:46 AM 0
Share

omg, I don't know why it won't format correctly >.<

avatar image bpears · Sep 05, 2012 at 04:32 AM 0
Share

poo, I'm gettin errors with this code, is it meant to replace the code or only part? New to scripting :(

avatar image purplelilgirl · Sep 05, 2012 at 04:46 AM 0
Share

only parts, what kind of errors are you getting?

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

8 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

Is there something wrong with my c# script? 1 Answer

Leaderboard GUISkin? 1 Answer

Highscore GUI not working properly help 0 Answers

Using GUI skin with my GUI Button 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