Version: 2021.1
言語: 日本語

説明

OnParticleTrigger is called when any particles in a Particle System meet the conditions in the trigger module.

これは、衝突範囲の内側か外側にあるパーティクルを削除、または、修正するために使用されます。

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class TriggerScript : MonoBehaviour { void OnParticleTrigger() { ParticleSystem ps = GetComponent<ParticleSystem>();

// particles List<ParticleSystem.Particle> enter = new List<ParticleSystem.Particle>(); List<ParticleSystem.Particle> exit = new List<ParticleSystem.Particle>();

// get int numEnter = ps.GetTriggerParticles(ParticleSystemTriggerEventType.Enter, enter); int numExit = ps.GetTriggerParticles(ParticleSystemTriggerEventType.Exit, exit);

// iterate for (int i = 0; i < numEnter; i++) { ParticleSystem.Particle p = enter[i]; p.startColor = new Color32(255, 0, 0, 255); enter[i] = p; } for (int i = 0; i < numExit; i++) { ParticleSystem.Particle p = exit[i]; p.startColor = new Color32(0, 255, 0, 255); exit[i] = p; }

// set ps.SetTriggerParticles(ParticleSystemTriggerEventType.Enter, enter); ps.SetTriggerParticles(ParticleSystemTriggerEventType.Exit, exit); } }

In order to retrieve detailed information about all the collisions caused by the ParticleSystem, ParticlePhysicsExtensions.GetTriggerParticles must be used to retrieve the array of Particle.