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 MrHasuu · Jun 24, 2012 at 02:39 AM · spritestransparentfadeout

fading with sprites?

I'm currently working with a 2d game with sprites and i'm using ex2d for the 2D sprites. I wanted to make a sprite i created to fade from visible to transparent,and i was wondering how to do it. the first thing that came to mind was using the iTween.FadeTo function which gave me an error, i did some searching and noticed i needed Transparent/diffuse type of shader or something close to it. Unfortunately ex2d sprites use the customed ex2d/alpha blended shader which resulted in the error, and changing the shader to transparent/diffuse obviously doesn't help. is there a way to do it? or am i just going about it wrong?

Comment
Add comment · Show 1
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 whydoidoit · Jun 24, 2012 at 02:41 AM 0
Share

Does the shader have a color that you can set?

2 Replies

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

Answer by delstrega · Jun 24, 2012 at 05:47 AM

Just use the standard ex2d/alpha blended shader and change the exSprites color's alpha value.

Some example code (slap that onto the sprite you want to fade):

FadeMe.js:

 #pragma strict
 
 var mySprite : exSprite;
 var fadeValue : float = 1;
 var currentTime: float = 0;
 var timeItTakesToFade = 1;
 var isFading : boolean = false;
 
 function Start () {
     mySprite = GetComponent(exSprite);
     StartFade(5);
 }
 
 function Update () {
     if(isFading){
         
         currentTime += Time.deltaTime;
         
         if(currentTime <= timeItTakesToFade){
             fadeValue = 1 - (currentTime / timeItTakesToFade);
             mySprite.color = Color(1,1,1, fadeValue);
         }else{
             isFading = false;
         }
     }
     
 }
 
 function StartFade (howLong : float) {
     currentTime = 0;
     timeItTakesToFade = howLong;
     isFading = true;
 }

This is just an example to get you started :)

Hope that helps,

delstrega

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 whydoidoit · Jun 24, 2012 at 05:50 AM 1
Share

@delstrega - I figured the shader must have an alpha - glad you knew it did!

avatar image delstrega · Jun 24, 2012 at 06:39 AM 0
Share

@whydoidoit - :D

avatar image
1

Answer by MrHasuu · Jun 25, 2012 at 05:40 AM

This was exactly what i needed, thank you so much!

anyway so this was what i ended up with in the end: my goal was to have an object pulsing on the screen, but theres several versions of it and i didnt want to import pulsing animation with sprites which means a bunch of png being added in. So for anyone else who may need this in the future here's what I ended up with in C#

 private float time = 10.0f;
 
 private exSprite temp;
 private float fadeValue = 1f;
 private float currentTime = 0f;
 private const float timeItTakesToFade = 0.5f;
 private bool isFading = false;
 private bool isAppearing = false;
 
 void Start() {
     temp = gameObject.GetComponent<exSprite>();
     StartFade();
 }
 
 void Awake() {
     Destroy(gameObject, time);
 }
 
 void Update() {
     if(isFading){
         currentTime += Time.deltaTime;
            if(currentTime <= timeItTakesToFade){
              fadeValue = 1f - (currentTime / timeItTakesToFade);
              temp.color = new Color(1f,1f,1f, fadeValue);
            }else{
             isFading = false;
             StartAppear();
            }
     }
     
     if(isAppearing){
         currentTime += Time.deltaTime;
         if(currentTime <= timeItTakesToFade) {
             fadeValue = 1f + (currentTime / timeItTakesToFade);
             temp.color = new Color(1f, 1f, 1f, fadeValue);
         }else{
             isAppearing = false;
             StartFade();
         }
     }
 }
 
 private void StartFade() {
     currentTime = 0;
     isFading = true;
 }
 
 private void StartAppear() {
     currentTime = 0;
     isAppearing = true;
 }
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 MicNit · Apr 04, 2013 at 06:25 PM 0
Share

Hello $$anonymous$$rHasuu!

I think there is an error in your code.

Replace this (line 34):

 fadeValue = 1f + (currentTime / timeItTakesToFade);
  

with:

 fadeValue = currentTime / timeItTakesToFade;

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Why is everything in my Scroll View Viewport transparent? 2 Answers

How to prevent transparent objects overlap 0 Answers

Removing backgrounds from leaf in pictures. 0 Answers

Semi-Transparent Sprite over another Sprite? 1 Answer

How to prevent alpha channel from anti-aliasing? 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