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 PaxStyle · Aug 22, 2013 at 10:16 AM · resolutionmenumain

Problem Resolution

Hi to all.. I created a main menu, in unity editor it's all right http://imageshack.us/a/img542/4328/3h4h.png , but when I build the game, the position of the public 2D Texture that I had put, are all wrong..(http://imageshack.us/a/img29/2083/lqgf.png) in all resolution, they change position... How can I block their position? I have to set fixed resolution? any ideas?

This is the script:

 using UnityEngine;
 using System.Collections;
 
 public class MenuCompleto : MonoBehaviour {
     
     public AudioClip suono;
     public GUISkin PersonalizzaBottone1;
     public GUISkin PersonalizzaBottone2;
     public GUISkin PersonalizzaBottone3;
     public GUISkin PersonalizzaBottone4;
     public bool Mostamenu;
     public bool MostraFinestraOpzioni = false;
     public Texture sfondo;
     public Texture AidaGames;
     public Texture MainMenu;
     public Texture RideSimulator;
     
     // Use this for initialization
     void Start () 
     {
         Mostamenu = true;
         Screen.fullScreen = !Screen.fullScreen;
     }
     
     // Update is called once per frame
     void Update () 
     {
     
     }
     
     void OnGUI ()
     {
         GUI.DrawTexture(new Rect(0,0,1920,1080),sfondo);
         GUI.DrawTexture(new Rect(1075,540,200,100),AidaGames);
         GUI.DrawTexture(new Rect(100,80,250,80),MainMenu);
         GUI.DrawTexture(new Rect(600,80,600,250),RideSimulator);
         
         if(Mostamenu)
         {
             GUI.skin = PersonalizzaBottone1;
             if(GUI.Button(new Rect(100,200,200,70),""))
             {
                 GUI.Button(new Rect(100,200,200,70),"");
                 audio.PlayOneShot(suono);
                 Mostamenu = false;
                 Application.LoadLevel("livello1");
             }
             GUI.skin = PersonalizzaBottone2;
             if(GUI.Button(new Rect(100,280,200,70),""))
             {
                 GUI.Button(new Rect(100,280,200,70),"");
                 audio.PlayOneShot(suono);
                 Mostamenu = false;
                 
             }
             GUI.skin = PersonalizzaBottone3;
             if(GUI.Button(new Rect(100,360,200,70),""))
             {
                 GUI.Button(new Rect(100,360,200,70),"");
                 audio.PlayOneShot(suono);
                 MostraFinestraOpzioni = true;
                 Mostamenu = false;
                 
             }
             GUI.skin = PersonalizzaBottone4;
             if(GUI.Button(new Rect(100,440,200,70),""))
             {
                 GUI.Button(new Rect(100,440,200,70),"");
                 audio.PlayOneShot(suono);
                 Mostamenu = false;
                 Application.Quit();
             }
         }
         if(MostraFinestraOpzioni)
         {
             GUI.Window(0,new Rect(Screen.width / 2 - 250 ,Screen.height / 2 - 125,500,150),Opzioni,"Opzioni");
         }
     }
     
     void Opzioni (int id)
     {
         if(GUILayout.Button("Video"))
         {
             Debug.Log("Tasto Video Premuto");
         }    
         GUILayout.Button("Audio");
         GUILayout.Button("Comandi");
         if(GUILayout.Button("Chiudi"))
         {
             audio.PlayOneShot(suono);
             MostraFinestraOpzioni = false;
             Mostamenu = true;
         }
         
     }
 }
 
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by fafase · Aug 22, 2013 at 10:18 AM

This is probably due to your Free Aspect resolution. Top left of the Game view is a drop down that allows to select a particular resolution.

This helps to get the appropriate resolution for various devices.

Also, it is better to use Screen.height/width to make sure something shows up and rescale automatically.

Comment
Add comment · Show 9 · 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 PaxStyle · Aug 22, 2013 at 12:06 PM 0
Share

So you should me to remove display resolution dialog? And set a specific graphic size? (in the settings when I build the game) I tried the game in another PC (more small) with the fixed resolution,and not work well! :( the menu's images are cut.. :(

avatar image fafase · Aug 23, 2013 at 11:55 AM 0
Share

That is what I am telling you. If you set an object at 900,0, on a 1280/960 it goes fine, on a screen, on a 640/480 it is out of the screen. If ins$$anonymous$$d you had used:

x = Screen.width / 10 * 9;

Then whatever the resolution is, the button will get at 9/10 of the screen. Use the same process for the size of the rect and everything will automatically scale to the screen.

avatar image PaxStyle · Aug 23, 2013 at 12:16 PM 0
Share

But where should I put this part of script? (x = Screen.width / 10 * 9;) sorry for the stupid question..

 GUI.DrawTexture(new Rect(0,0,1920,1080),image);
avatar image fafase · Aug 24, 2013 at 06:10 AM 0
Share

Let's say you want a square box with side 1/2 of the width of the screen to be right in the middle.

 Rect box;
 void Start(){
     float edge = Screen.width / 2;
     // xPos is from the middle
     float xPos = Screen.width / 2 - edge / 2;
     float yPos = Screen.height / 2 - edge / 2;
     box = new Rect(xPos, yPos, edge, edge);
 }
 void OnGUI(){
     GUI.DrawTexture(box, image);
 }

I recommend to do that on the Start as it makes the method clearer to me. Also, storing values in variables like edge allows you to have a quick way to modify the size without changing many values.

If for instance, you want your box to be two third of the screen ins$$anonymous$$d of one half, you only do:

 float edge = Screen.width / 3 * 2;

and the rest will follow.

avatar image PaxStyle · Aug 24, 2013 at 11:03 AM 0
Share

But so the image seen at the middle of the screen.. I hadn't ask for the middle, but in a specific fixed position.. :)

Show more comments
avatar image
0

Answer by Skibur · Aug 24, 2013 at 06:22 AM

Replace this

GUI.DrawTexture(new Rect(1075,540,200,100),AidaGames);

to:

GUI.DrawTextrue(new Rect(Screen.width - AidaGames.width - 10, Screen.height - AidaGames.height - 10, AidaGames.width, AdiaGames.height), AidaGames);

using Screen.width/Screen.height will automatically obtain the length and width of your game window, making your icon always at the corner of your screen no matter what.

The one you wrote is a fixed position meaning that no matter what you resize your game to, it will always draw at that coordinate that you assign the texture to.

Comment
Add comment · Show 2 · 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 fafase · Aug 24, 2013 at 06:24 AM 0
Share

You still have a 10 there in your solution. So partly fix this issue, this 10 will be 10 whatever the dimension. And why 10? why not 42 since it is always the answer.

avatar image Skibur · Aug 24, 2013 at 06:27 AM 0
Share

the 10 is making sure the icon isn't exactly at the corner, so it appears to be at the corner but with a little space inward of the window.

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

16 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

Related Questions

2D Game: main menu button dont work 0 Answers

How to make a half 2d- half 3d main menu?? 1 Answer

New Unity Dropdown Menu to Change Game Resolution 1 Answer

Passing a variable through the main menu 2 Answers

How do I make music continue through certain scenes 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