- Home /
 
 
               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
              
 
               
              Your answer
 
             Follow this Question
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