Version: 2022.3

ParticleSystem.SubEmittersModule.GetSubEmitterEmitProbability

切换到手册
public float GetSubEmitterEmitProbability (int index);

参数

index 子发射器的索引。

返回

float 子发射器的发射概率

描述

获取子发射器发射粒子的概率。

返回 0 到 1 之间的值,其中 0 表示从不,1 表示始终。

using UnityEngine;

public class Example : MonoBehaviour { void Start() { // A simple particle material with no texture. var particleMaterial = new Material(Shader.Find("Particles/Standard Surface"));

// Emit 1 particle per second. var particleSystemGameObject = new GameObject("Particle System"); var particleSystemMain = particleSystemGameObject.AddComponent<ParticleSystem>(); var emitMain = particleSystemMain.emission; emitMain.rateOverTime = 1; particleSystemGameObject.GetComponent<ParticleSystemRenderer>().material = particleMaterial;

// Create a sub-emitter that has a 10% chance of emitting a red particle when "Particle System" emits. var subEmitterGo = new GameObject("Sub Emitter"); subEmitterGo.transform.SetParent(particleSystemGameObject.transform); var subEmitter = subEmitterGo.AddComponent<ParticleSystem>(); var emitSub = subEmitter.emission; emitSub.rateOverTime = 0; emitSub.burstCount = 1; emitSub.SetBurst(0, new ParticleSystem.Burst(0, 1)); var mainModule = subEmitter.main; mainModule.startColor = Color.red; subEmitterGo.GetComponent<ParticleSystemRenderer>().material = particleMaterial;

// Add the sub-emitter, and set the probability. var subEmittersModule = particleSystemMain.subEmitters; subEmittersModule.enabled = true; subEmittersModule.AddSubEmitter(subEmitter, ParticleSystemSubEmitterType.Birth, new ParticleSystemSubEmitterProperties(), 0.1f); } }