• 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
1
Question by braisque · Apr 16, 2018 at 10:29 AM · scalespritessizequad

How to resize a quad to fit the dimensions of a sprite/.png ?

I'm building a 3D fps game, basically like the first doom. The thing is I want my "sprites" to cast shadow. So I have to put them in quads (I believe there's no other way to have the sprites cast shadows).

My first question is: Is it optimized to glue two quad together to have my sprites visible on each face ?

My second question is: If I put a .png in the game's assets, and I set the texture type to "Sprite (2D and UI), I can put this sprite in the game and the x and y sizes from the original .png are kept identical in the game. But I have to put the .pngs in quads and transform these .pngs to materials: But then I can't get the size and scale to be exactly the same as in the .png. Is there a non-manual way to set the size and scale of the quad to be the same as the original .png ?

Thank you for reading

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 selewi · Apr 16, 2018 at 11:11 AM

First of all, I think that if you want to use a quad with a sprite, you need to know about the billboarding technique, which makes a 2D sprite rotate towards the camera position, so you cannot see the "dark side of the sprite" huh :P.


You can set the scale and the size of a sprite by scripting using the quad bounds or the sprite bounds deppending on what you want to resize. Sorry I cannot help you with code right now, if you still need help with that I'll try to cover the code for you later, but I hope this is enough help. Cheers!

Comment
Add comment · Show 1 · 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 braisque · Apr 17, 2018 at 03:46 PM 0
Share

That is true. I indeed figured that I need to "billboard" some sprites and I figured how to do it.

I get your idea: If I'm correct, I shall, in a script, get the size of a sprite bound to a specific quad (in which I put the script) so it transforms that quad according to the sprite's size? Unfortunately, I can't figure out how to code that. I'm still not good enough to write that in C# ><. Could you help me ? Thank you anyway for the time you spent answering.

avatar image
0

Answer by BCook99 · Nov 23, 2020 at 08:30 PM

I recently ran into the same issue. In my project I imported the sprites png files as texture type Sprite 2D and set the pixel ratio to 1:1.

I then created a material using the sprite for the albedo and put it on a quad using a sprite shader. By setting the quad scale equal to the dimensions of the PNG file, it matched a 2D sprite display size perfectly.

In my example, the PNG file was 600x600 pixels and the quad scale was 600,600,1

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

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

Related Questions

Size And Scale Limitations 2 Answers

How to fit a background sprite with 4:3 aspect ratio in a 16:9 screen by simply making the extra content of the sprite from the bottom go outside the camera? 2 Answers

2d game questions 0 Answers

Way to evenly spawn X sprites within a 2D area so they scale to fit depending on screen size. 1 Answer

Why does this not scale smoothly? Any Ideas? Transform.localscale 2 Answers

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