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 Masterben135 · Jul 29, 2014 at 04:39 PM · spritestransparentsprite rendererhighlighting

Semi-Transparent Sprite over another Sprite?

In my tile-based game, I'm trying to get the effect of a tile showing it's selected by having it highlighted, but with the original sprite underneath. However, I can't have two sprite renderers attached to the same object to hold both Sprites (The Tile Sprite and the Highlight Sprite).

How can I overlay the sprites or combine them without making a "highlighted tile" for each individual tile?

Note: The Tiles fill a uniform tile size of 32x32 pixels, but some sprites go higher than this, i.e. 32x40. I need the entire 32x40 sprite to be highlighted, not a bunch of 32x32 squares. Here is where my problem really lies.

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

1 Reply

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

Answer by Lazdude17 · Jul 29, 2014 at 05:06 PM

You could just change the color in the sprite renderer to a specific color when selected. Or you could go more complicated and create an empty in front of your selected object every time it is selected then make that empty a child of the selected/real object. Assign this empty the same sprite as the selected object and change it's color on the empty with the sprite renderer. Then delete this object on "Not Selected".

 void Update()
 {
     if(SELECTED)
     {
         Transform highlightSprite = Instantiate(EMPTY WITH BLANK SPRITE RENDERER COMPONENT); //Save as a prefab
         highlightSprite.parent = this.transform;
         highlightSprite.GetComponent<SpriteRenderer>().sprite = highlightSprite.parent.GetComponent<SpriteRenderer>().sprite;
         highlightSprite.GetComponent<SpriteRenderer>().color = SPECIFIC COLOR CODE YOU WOULD LIKE WITH ALPHA
     }
     else
     {
         Destroy(highlightSprite.gameObject);
     }
 }

It's rough code and I would recommend splitting the code up between the two objects involved.

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 Masterben135 · Jul 29, 2014 at 06:16 PM 0
Share

I had a similar idea, and thanks for the great answer, but the problem is that I wanted the "highlight" to be an animated sprite all its own, but the problem with that is the non-uniform sprite sizes...

avatar image Masterben135 · Jul 29, 2014 at 07:01 PM 0
Share

After thinking about your answer, it turns out, I can make it work. Thanks again!

avatar image Lazdude17 · Jul 29, 2014 at 08:08 PM 0
Share

No problem. Yeah size shouldn't matter at all. If you are wanting the highlight to flash then just be sure to write a 'Flashing.cs or .js' script to animate the flash for you and attach it to the empty prefab and overwrite the prefab so that every instance of it has the flash on it.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Sprites Are Blurry 0 Answers

How can I change sprites in animation clip? 0 Answers

How do I make a working, tiling Sprite shader that works with 2D LWRP? 0 Answers

Unity 2D problem with displaying sprites in final build game 1 Answer

How to prevent transparent objects overlap 0 Answers


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