You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1.0 KiB
34 lines
1.0 KiB
using System.Collections; |
|
using System.Collections.Generic; |
|
using UnityEngine; |
|
|
|
/// <summary> |
|
/// This script demonstrate how to use the particle system collision callback. |
|
/// The sample using it is the "Extinguish" prefab. It use a second, non displayed |
|
/// particle system to lighten the load of collision detection. |
|
/// </summary> |
|
public class ParticleCollision : MonoBehaviour |
|
{ |
|
private List<ParticleCollisionEvent> m_CollisionEvents = new List<ParticleCollisionEvent>(); |
|
private ParticleSystem m_ParticleSystem; |
|
|
|
|
|
private void Start() |
|
{ |
|
m_ParticleSystem = GetComponent<ParticleSystem>(); |
|
} |
|
|
|
|
|
private void OnParticleCollision(GameObject other) |
|
{ |
|
int numCollisionEvents = m_ParticleSystem.GetCollisionEvents(other, m_CollisionEvents); |
|
for (int i = 0; i < numCollisionEvents; ++i) |
|
{ |
|
var col = m_CollisionEvents[i].colliderComponent; |
|
|
|
var fire = col.GetComponent<ExtinguishableFire>(); |
|
if (fire != null) |
|
fire.Extinguish(); |
|
} |
|
} |
|
}
|
|
|