• 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 SuperMasterBlasterLaser · Apr 25, 2014 at 11:29 AM · 2dspriteresolutionsizefixed

Keep sprites at fixed size

Hello.

I have GameObjects that will hold sprites. They will change their sprites at certain event. However, pixel sizes of sprites are different.

What I must write in script to keep all changed sprites in one size? (In pixels size is 263x163)

PS this game is on 2D mode.

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

3 Replies

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

Answer by robertbu · Apr 25, 2014 at 03:11 PM

If you want the sprites to be the same world size even if their pixel size is different, then you need to select the texture used for that sprite and set the 'Pixels to Units' value as appropriate to scale the sprite to the target size.

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 SuperMasterBlasterLaser · Apr 25, 2014 at 03:38 PM 0
Share

O$$anonymous$$, that works pretty fine. However, I need to set "Pixels to Units" for every image manually? Is there some kind of method to automatically do it in script using formula? Because my application got 1200 images.

avatar image robertbu · Apr 25, 2014 at 04:05 PM 0
Share

You can probably do it with an editor script. But considering the number of images, maybe you just want to scale the images at runtime. Assuming uniform scaling and a 'targetHeight' in world units, you can do:

 var bounds = GetComponent(SpriteRenderer).sprite.bounds;
 var factor = targetHeight / bounds.size.y;
 transform.localScale = Vector3(factor, factor, factor);
 
avatar image robertbu · Apr 25, 2014 at 04:15 PM 0
Share

I don't know your game mechanic, but two other things to consider. If you can use a Quad for your image ins$$anonymous$$d of a sprite, your problem goes away. And alternately (and not without some pitfalls), you would use a batch script in Photoshop to bring your images that need to be the same size to the same resolution.

avatar image
0

Answer by richard_Richintellect · Jan 20, 2017 at 04:16 PM

Just change the "pixels per unit" per sprite. To select multiple sprites use the command button (on a mac).

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

Answer by unityPashok · Sep 06, 2020 at 02:13 PM

  1. Create a canvas

  2. Create a panel in canvas

  3. Create a image in panel

  4. drag first image from your sprite sheet to source image form image

  5. Click on 'Window=>Animation=>Animation (or Ctrl+6)'

  6. Click on your image from panel

  7. Click on Create button from Animation window (now you need to save your clip in a folder)

  8. After creating clip (click on red circle button) and you can drag your sprite sheet on Animation window

  9. Click on red circle button, ready

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

22 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

Related Questions

Problems assigning sprite's images 1 Answer

How to make sprites occupy the same screen space on different resolutions ? 1 Answer

What Size To Make Art Assets? 1 Answer

Sprite Image size for different mobile resolutions 0 Answers

How can I set the position and size of a sprite from inside a script ? 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges