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 diogm · May 30, 2014 at 07:26 PM · objectspositioningscreen.widthscreen.height

Positioning across various resolutions

Hi, i'm instantiating some objects dynamically and I can't position them correctly across different resolutions.

 void generateSequence(){
 
         System.Random rand = new System.Random (); 
         Texture2D[] cardTex = cardList.ToArray();
         Texture2D[] baloonsTex= baloonsList.ToArray();
 
         GameObject txt = Instantiate(TextPrefab) as GameObject;
         txt.guiText.text = "Try to memorize...";
         txt.name = "mem_text";
         txt.transform.position = new Vector3 (Screen.width * 0.0003f, Screen.height * 0.00083f, 0);
         txt.guiText.fontSize = 50;
 
 
         cardSeq = new GameObject[numCards];
 
         float x = (Screen.width * 0.00052f)/numCards;
         float y = (Screen.height * 0.00053f);
 
         float pixelX = Screen.width * 0.20f;
         float pixelY = Screen.height * 0.56f;
         int b = 0;
         int listLength;
 
         if(difficulty==3) b=1;
 
         for (int i=0; i<numCards; i++) {
             
             GameObject card = Instantiate(cardSeqPrefab,new Vector3(x,y,0), Quaternion.identity )as GameObject;
             if(difficulty==2)
                 b = rand.Next(2);
             Texture2D auxTex;
             listLength = rand.Next(cardTex.Length);
             if(b==0)
                 auxTex = cardTex[listLength];
             else auxTex=baloonsTex[listLength];
 
             card.guiTexture.texture=auxTex;
             
             card.guiTexture.pixelInset = new Rect(0,0,Screen.width * 0.18f,Screen.height * 0.27f);
             nameIt(card, listLength);
 
             if(!start){
                 GameObject empty_card = Instantiate(cardSeqPrefab,new Vector3(x,y,0), Quaternion.identity  )as GameObject;
                 empty_card.guiTexture.texture = empty_card_tex;
                 empty_card.guiTexture.pixelInset = new Rect(0,0,Screen.width * 0.14f,Screen.height * 0.27f);
                 empty_card.SetActive(false);
                 empty_card.name = i+"empty";
                 empty_card.layer = 2;
                 emptiness[i]=empty_card;
             }
 
             cardSeq[i] = card;
             x = x + (Screen.width * 0.0001f);
             card.layer = 2;
 
         }
         start = true;
         AudioClick.Instance.Play (SOUNDS.FLIP_CARD);
         countdown = 5f;
         state = (int)_gameState.Memorizing;
     }

There's some lines in this code that do not add up for the position but I wanted to paste the whole function. Ok, so on my pc it gets the correct positioning, but I tried on my brother's laptop and the objects got out of place. What can I do to fix this problem? Thanks!

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

0 Replies

· Add your reply
  • Sort: 

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

20 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

Related Questions

Screen height and width confusion 1 Answer

Unity 3.5.7 Android Screen returns the wrong value? 0 Answers

How to set screen boundaries on a moving camera 1 Answer

Screen.width and Screen.height sometimes flipped for Android 1 Answer

Touchscreen input: Moving the player using screen.width & screen.height 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