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 uanmanarmy · Jul 16, 2014 at 01:58 PM · scalespritesscreenfit

Objects to fit on the screen

Hello guys/girls I need a little bit of help here.

I had placed on the top of the screen some items that you can found them on the ground like weapons etc.

The problem is that when they are less or equal to 3 they can fit on the screen, but if they are more than 3 they just go trough borders.

Here is an example to be more clear alt text

I need a way to scale them down or to scale them just a little bit and to put on two rows.

Any help will be appreciated.

Here is my code to instantiate them

 public void CreateItems(float i, int numberOfObjects, float iterator, float offsetX, float yPosition, GameObject itemPrefab)
     {
         numberOfObjects = objectScript.ItemsNumber;
         string letter = objectScript.ItemsColor;
         GameObject cube = null;
 
         switch(letter)
         {
         case "B":
             cube = Item_bbg;
             break;
         
         case "G":
             cube = Item_gbg;
             break;
         
         case "O":
             cube = Item_obg;
             break;
 
         case "P":
             cube = Item_pbg;
             break;
         case "R":
             cube = Item_rbg;
             break;
         case "Y":
             cube = Item_ybg;
             break;
 
         default: break;
         }
         //impar
         if(numberOfObjects % 2 != 0)
         {
             iterator = -numberOfObjects +1;
             offsetX = 2f;
 
                 for(i = iterator; i < numberOfObjects  ; i += offsetX)
                 {
                     GameObject clone = Instantiate (cube, new Vector3 (i , yPosition, -1), Quaternion.identity) as GameObject;
                     prefabs.Add(clone);
                 }
         }
         
         //par
         else 
         {
             iterator = - numberOfObjects +1;
             offsetX = 2.0f;
             if(numberOfObjects !=0 )
             {
                 for(i = iterator; i < numberOfObjects ; i += offsetX)
                 {
                     GameObject clone = Instantiate (cube, new Vector3 (i , yPosition, -1), Quaternion.identity) as GameObject;
                     prefabs.Add(clone);
                 }
             }
         }
 
         // Check for exceptions case
         if(numberOfObjects == 0)
         {
             return;
         }
 
     }
безымянный.png (16.8 kB)
Comment
Add comment · Show 2
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 Issah · Jul 16, 2014 at 03:57 PM 0
Share

Hi,

You want to make an inventory ? Personnaly i do it with a GUI.Window :

 void OnGUI() 
 {
     windowRect = GUI.Window(0, windowRect, Do$$anonymous$$yWindow, " Window");
 }
 void Do$$anonymous$$yWindow(int windowID) 
 {
     // Item Container
 }

 

The windowRect is the inventory and the object of DomyWindow never go out of the main window ( windowRect ).

I'm a beginner, i hope it will help....

avatar image uanmanarmy · Jul 16, 2014 at 05:02 PM 0
Share

I have to check it tomorrow.

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Exbow · Jul 16, 2014 at 05:45 PM

if you are using an orthographic camera i would suggest you to create a script in which you technically calculate the width of the screen like that

 left = Camera.main.ScreenToWorldPoint(new Vector3(0,"put any height you want", Camera.main.transform.position.z));
 right = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width,"same height here", Camera.main.transform.position.z));
  

 List<itemsIwannaInclude> myItems = new List<itemsIwannaInclude>();
   

 step =(Mathf.Abs(left.x) + Mathf.Abs(right.x)/ (myItems.Count);

   
 float ourScale = ((step * myItems.Count) / (tile.renderer.bounds.size.x * myItems.Count));
    
 for(int i = 0; i < myItems.Count; i ++)
 {
     myItems[i].transform.localScale = new Vector3(ourScale ,ourScale ,"whatever value");
 
 }
 
 

hope that helps.

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 uanmanarmy · Jul 17, 2014 at 07:32 AM 0
Share

that's not right.

Imagine you will have an ScreenWidth of 1000 and 10 Items

The ourItemSize will be 100. And if you scale all of the Items by 100 on both axes than will just blow up .

avatar image Exbow · Jul 17, 2014 at 03:38 PM 0
Share

i've updated my answer, hope that helps.

avatar image
1

Answer by Radu001 · Jul 17, 2014 at 07:30 AM

Set the position of the first 3 on the screene, and if you have more you can just slide to view others,using NGUI or something write by you.Scaling is not a good idea.

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

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

Related Questions

Values are changing but the scale of sprite no. 1 Answer

A node in a childnode? 1 Answer

GUI texture to fit the screen at any resolution? 4 Answers

How to get the screen position in an unlit shader. 1 Answer

Scaling a menu bar 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