Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Tohron · Sep 07, 2013 at 10:48 PM · particlesparticlesystem

How to Slowly Fade Particle System via Script

Okay, I've got a looping particle system that emits expanding donuts of particles (in bursts), and already uses Color over Lifetime to change their color and fade them out shortly before their lifetime ends.

However, I also want to make the entire particle system slowly fade out at a rate defined in a script (the system would be attached to a shotgun-like attack, and the fading would represent the diminishing damage potential of the attack). However, I can't seem to find a way to do this. Any ideas?

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
3

Answer by brilliancenp · Feb 27, 2014 at 11:33 PM

You would need to access the particle system by attaching a monobehavior script to it. You can get access to it using:

 //This sets up an array container to hold all of the particles
 ParticleSystem.particle[] particles = new ParticleSystem.Particle[particleSystem.particleCount];
 
 //get the particles
 particleSystem.GetParticles(particles);
 
 //then iterate through the array changing the color 1 by 1
 for(int p = 0; p < particles.Length; p++)
 {
     particles[p].color = new Color32(r, g, b, a);//where a = the alpha
 }
 
 //set the particles back to the system
 particleSystem.SetParticles(particles, particles.Length);

This will be done in the Update method and would allow the uniform fade for all particles in the system I think you are looking for. This code is off the top of my head so it may not be perfect, but should give you the correct idea and syntax.

You would need to either have a global alpha variable and decrement it over time and apply it to the new Color32 each frame or get the current particle color and decrement the alpha overtime.

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
2

Answer by Jonesy19 · Jan 25, 2017 at 03:23 PM

I was looking for an answer to this same problem, but the solution above cost too much cpu power for my particular instance. Instead, I decided to change the start color of the particle system over time, rather than go through every single particle. This worked in my case, as the particles were moving and emitting so fast that it gave the same effect...Anyways, here is some sample code...Note that ps.startColor is deprecated now, but you get the idea...

 private void fadeParticleSystem()
     {
         Color col = deathRayOrbPs.startColor;
         Debug.Log("Initial Color: " + col.a);
         col.a -= col.a * colorFadeDampner * Time.deltaTime;
         Debug.Log("Color: " + col.a);
         deathRayOrbPs.startColor = col;
     }
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.

Follow this Question

Answers Answers and Comments

17 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

Related Questions

Can I slow down a Particle System? - e.g. Slow Motion Effect 1 Answer

Problem using point.Length in a particle system c# 2 Answers

How do I pull particles towards the player? (Javascript) 0 Answers

particleSystem.Play(); wont start 1 Answer

Unity Update Broke My Project: IsFinite(Some Text) 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