파티클 시스템은 씬에서 한 개 이상의 콜라이더와 상호작용할 때마다 콜백을 트리거할 수 있습니다. 파티클이 콜라이더에 들어가거나 빠져 나올 때, 또는 콜라이더의 내부나 외부에 있는 동안 콜백이 트리거될 수 있습니다.
파티클이 콜라이더에 들어갈 때 파티클을 파괴하는 간단한 방법(예: 빗방울이 옥상에 닿지 않도록)으로 콜백을 사용하거나, 일부 또는 모든 파티클의 프로퍼티를 수정하기 위해 콜백을 사용할 수 있습니다.
트리거(Triggers) 모듈에는 소멸(Kill) 옵션이 있으므로 파티클을 자동으로 제거할 수도 있으며, 무시(Ignore) 옵션을 사용하면 아래와 같이 충돌 이벤트를 무시할 수도 있습니다.
이 모듈을 사용하려면 우선 트리거를 생성할 콜라이더를 추가한 다음, 사용할 이벤트를 선택해야 합니다.
다음 조건에 파티클이 해당할 경우 이벤트를 트리거하도록 설정할 수 있습니다.
프로퍼티: | 기능: |
---|---|
Inside | 파티클이 콜라이더 내부에 있을 때 이벤트를 트리거하려면 콜백(Callback)을 선택합니다. 파티클이 콜라이더 내부에 있을 때 이벤트를 트리거하지 않으려면 무시(Ignore)를 선택합니다. 콜라이더의 파티클을 파괴하려면 소멸(Kill)을 선택합니다. |
Outside | 파티클이 콜라이더 외부에 있을 때 이벤트를 트리거하려면 콜백(Callback)을 선택합니다. 파티클이 콜라이더 외부에 있을 때 이벤트를 트리거하지 않으려면 무시(Ignore)를 선택합니다. 콜라이더 외부의 파티클을 파괴하려면 소멸(Kill)을 선택합니다. |
Enter | 파티클이 콜라이더에 진입할 때 이벤트를 트리거하려면 콜백(Callback)을 선택합니다. 파티클이 콜라이더에 진입할 때 이벤트를 트리거하지 않으려면 무시(Ignore)를 선택합니다. 콜라이더에 진입하는 파티클을 파괴하려면 소멸(Kill)을 선택합니다. |
Exit | 파티클이 콜라이더를 벗어날 때 이벤트를 트리거하려면 콜백(Callback)을 선택합니다. 파티클이 콜라이더를 벗어날 때 이벤트를 트리거하지 않으려면 무시(Ignore)를 선택합니다. 콜라이더를 벗어나는 파티클을 파괴하려면 소멸(Kill)을 선택합니다. |
Radius Scale | 이 파라미터는 파티클 콜라이더의 범위를 설정하므로 파티클이 콜라이더에 접촉하기 전이나 후에 이벤트가 발생할 수 있습니다. 예를 들어, 충돌이 일어나기 전에 파티클이 콜라이더 오브젝트의 표면을 통과하는 것으로 표시되도록 할 수 있습니다. 이 경우 반지름 스케일을 1보다 약간 작게 설정합니다. 이벤트가 실제로 발생하면 이 설정이 변경되지 않습니다. 하지만 이 설정으로 인해 트리거의 시각 효과를 지연시키거나 향상시킬 수 있습니다. - 파티클이 콜라이더에 접촉할 때 이벤트가 나타나도록 하려면 1을 입력합니다. - 파티클이 콜라이더를 통과한 후에 트리거가 나타나도록 하려면 1보다 작은 값을 입력합니다. - 파티클이 콜라이더를 통과한 후에 트리거가 나타나도록 하려면 1보다 큰 값을 입력합니다. |
Visualize Bounds | 이 옵션을 사용하면 에디터 창에서 파티클 콜라이더의 범위를 표시할 수 있습니다. |
콜백 내부에서 지정할 ParticleSystemTriggerEventType과 함께 ParticlePhysicsExtensions.GetTriggerParticles()를 사용하여 기준에 맞는 파티클을 결정해야 합니다.
아래의 예제에서 파티클은 콜라이더에 진입할 때 빨간색으로 변한 다음, 콜라이더의 범위를 벗어날 때 다시 녹색으로 변합니다.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
[ExecuteInEditMode]
public class TriggerScript : MonoBehaviour
{
ParticleSystem ps;
// these lists are used to contain the particles which match
// the trigger conditions each frame.
List<ParticleSystem.Particle> enter = new List<ParticleSystem.Particle>();
List<ParticleSystem.Particle> exit = new List<ParticleSystem.Particle>();
void OnEnable()
{
ps = GetComponent<ParticleSystem>();
}
void OnParticleTrigger()
{
// get the particles which matched the trigger conditions this frame
int numEnter = ps.GetTriggerParticles(ParticleSystemTriggerEventType.Enter, enter);
int numExit = ps.GetTriggerParticles(ParticleSystemTriggerEventType.Exit, exit);
// iterate through the particles which entered the trigger and make them red
for (int i = 0; i < numEnter; i++)
{
ParticleSystem.Particle p = enter[i];
p.startColor = new Color32(255, 0, 0, 255);
enter[i] = p;
}
// iterate through the particles which exited the trigger and make them green
for (int i = 0; i < numExit; i++)
{
ParticleSystem.Particle p = exit[i];
p.startColor = new Color32(0, 255, 0, 255);
exit[i] = p;
}
// re-assign the modified particles back into the particle system
ps.SetTriggerParticles(ParticleSystemTriggerEventType.Enter, enter);
ps.SetTriggerParticles(ParticleSystemTriggerEventType.Exit, exit);
}
}
위의 예제의 결과는 아래 그림과 같습니다.
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.