Maximum number of particles in a Unity notes modulated particle system

Source: Internet
Author: User
Tags emit

Unity the particle system is very easy to use. Such a problem is encountered in the actual process: the maximum number of particles that can be produced in order to control the dynamic needs of the particle system components.

Look at Doc, he says, there's maxparticles control. But there is no such open parameter. Can only be done in other ways.

This can be achieved by manually generating particles. Also known as the Emit method in Particlesystem, detailed code such as the following:

public class Particlesystemcomp:monobehaviour{particlesystem Mparticlesystem = Null;int mmaxparticles = 0;public int max Particles{get{return Mmaxparticles;} Set{mmaxparticles = value;}} void Awake () {Mparticlesystem = This.gameobject.getcomponent<particlesystem> (); mparticlesystem.emissionrate = 0.0f;mmaxparticles = Mparticlesystem.particlecount;mparticlesystem.clear ();} void Update () {if (Mparticlesystem! = null) {if (Mparticlesystem.particlecount < mmaxparticles) {Mparticlesystem.emit (Mmaxparticles-mparticlesystem.particlecount);}}}

The implementation process is for each particlesystem to add an additional component to the original PS update through that component.

The update principle is to infer the number of particles currently active, assuming that the number of particles is less than the specified maximum value, and then generate several new particles to fill.

In addition For performance reasons. Operations inside the update can also be moved to Fixedupdate to reduce the number of updates. But it does not bring much difference in vision.

Copyright notice: This article Bo Master original articles, blogs, without consent, may not be reproduced.

Maximum number of particles in a Unity notes modulated particle system

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.