Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 JonnyRave · Oct 21, 2018 at 04:07 AM · particlescolorgradient

Lerp an Alpha Gradient in Particle System Color over lifetime In script

I'm using a snow particle effect, on a 2d map and transition to rain and others depending on where your at on the map. problem I'm facing is the snow stays too long and looks sloppy when in areas it shouldn't be. I cant just set the color over lifetime alpha because the lifetime itself is too long. It needs to be so the particles don't disappear in the middle of the screen too early. I've tried changing the alpha in script but the sudden change in alpha does not look good. I've been playing with gradient keys, canvas groups and lerping methods to no avail. does anyone have any idea if you can lerp from one gradient alpha to another, I've found plenty of resources on color.lerp but not for the alpha. oddly enough I got mathf.pingpong to give me the effect i wanted but it would constantly swap back and forth between alpha 0 and 255 which I assume is correct hence "pingpong" although when replaced with the lerp method it didn't do anything except change alpha from 255 to 250..not sure why..

Heres what I have, this is called in the start method I need to add the alpha change in the //Show snow section

 private IEnumerator ShowEnvironmentParticleCo()
     {
         //Rain Particle System
         ParticleSystem rainParticle = rain.GetComponent<ParticleSystem> ();
         var rainEm = rainParticle.emission;
 
         //Mist Particle System
         ParticleSystem mistParticle = mist.GetComponent<ParticleSystem> ();
         var mistEm = mistParticle.emission;
         var mainMist = mistParticle.main;
         var mistColor = mistParticle.colorOverLifetime;
         Gradient ourGradient;
         ourGradient = new Gradient ();
 
         //Snow Particle System
         ParticleSystem snowParticle = snow.GetComponent<ParticleSystem> ();
         var snowEm = snowParticle.emission;
 
         //Snow Particle System 2
         ParticleSystem snowParticle2 = snow2.GetComponent<ParticleSystem> ();
         var snowEm2 = snowParticle2.emission;
         var snowColor2 = snowParticle2.colorOverLifetime;
 
         //Flash Particle System
         ParticleSystem flashParticle = flash.GetComponent<ParticleSystem> ();
         var flashEm = flashParticle.emission;
 
         //Show Rain based on scroll rect position
         if (scrollBar.value > 0.13 && scrollBar.value < 0.3) 
         {

             rainEm.enabled = true;
             GameObject.Find ("RainPrefab2D").GetComponent<AudioSource> ().enabled = true;
         } 
         else 
         {
             rainEm.enabled = false;
             GameObject.Find ("RainPrefab2D").GetComponent<AudioSource> ().enabled = false;
         }
 
         //Show Mist based on scroll rect position
         if (scrollBar.value > 0.59 && scrollBar.value < 0.86) 
         {
             mistEm.enabled = true;
             mainMist.simulationSpeed = 0.25f;
 
             //Change Mist Alpha
             ourGradient.SetKeys (
                 new GradientColorKey[] { new GradientColorKey (Color.white, 1.0f), new GradientColorKey (Color.white, 1.0f) },
                 new GradientAlphaKey[] { new GradientAlphaKey (0.3f, 0.0f), new GradientAlphaKey (0.0f, 1.0f) });
             
             mistColor.color = ourGradient;
         } 
         else if (scrollBar.value > 0.13 && scrollBar.value < 0.3) 
         {
             mistEm.enabled = true;
             mainMist.simulationSpeed = 1f;
 
             //Change Mist Alpha Back
             ourGradient.SetKeys (
                 new GradientColorKey[] { new GradientColorKey (Color.white, 1.0f), new GradientColorKey (Color.white, 1.0f) },
                 new GradientAlphaKey[] { new GradientAlphaKey (0.15f, 0.0f), new GradientAlphaKey (0.0f, 1.0f) });
             
             mistColor.color = ourGradient;
         } 
         else 
         {
             mistEm.enabled = false;
         }
 
         //Show Snow based on scroll rect position
         if (scrollBar.value > 0.75 && scrollBar.value < 0.94) 
         {
             snowEm.enabled = true;
             snowEm2.enabled = true;
         }
         else 
         {
             snowEm.enabled = false;
             snowEm2.enabled = false;
 
             //after disabling snow particle emission I would like to lerp from alpha 255 to 0 to quickly fade out the remaining particles here
         }
 
         //Show Flash based on scroll rect position
         if (scrollBar.value > 0.96 && scrollBar.value <= 1) 
         {
             flashEm.enabled = true;
         }
         else 
         {
             flashEm.enabled = false;
         }
 
         yield return new WaitForSeconds (2);
     }
Comment
Add comment · Show 3
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 ifurkend · Oct 21, 2018 at 05:17 AM 1
Share

It is much easier to lerp the _TintColor alpha of the snow material (assu$$anonymous$$g your snow mat uses non-mobile particle alpha blended shader).

avatar image JonnyRave ifurkend · Oct 22, 2018 at 03:08 AM 0
Share

They are mobile/particles/additive, but its okay, i found a work around and just commented my solution. I'll definitely remember that though, I didn't know you could change alphas of the materials in the project themselves.

avatar image JonnyRave · Oct 22, 2018 at 03:03 AM 0
Share

Update:

I just found a work around, after setting particle emission to false i used main.simulationspeed and set it higher so that the remaining particles fade away at a reasonable speed. I can't believe i didn't think of it earlier because I already used main.simulationspeed in this code to slightly change the speed of my mist particle. It doesnt look as good but it worked perfect for another particle i created (sunlight rays). the change in speed is hardly noticed but with the snow its a lil different but itll do for now.

However I am still interested in knowing how you could lerp a gradient alpha key if anyone knows, if not, no big deal.

0 Replies

· Add your reply
  • Sort: 

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

97 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 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

Change prefab color when shuriken particle touches it 1 Answer

Why am I having particle bad colors on some Android devices? 1 Answer

Does Material.color, ParticleSystem.startcolor property clones/copies the material? 2 Answers

Gradient Background With Random Color Lerp 0 Answers

How can I make an animated color gradient? 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