1 using System;
2 using
UnityEngine;
3
4 namespace
UnityStandardAssets.Effects
5 {
6     
public class WaterHoseParticles : MonoBehaviour
7     {
8         
public static float lastSoundTime;
9         
public float force = 1;
10
11
12         
private ParticleCollisionEvent[] m_CollisionEvents = new ParticleCollisionEvent[16];
13         
private ParticleSystem m_ParticleSystem;
14
15
16         
private void Start()
17         {
18             m_ParticleSystem = GetComponent<ParticleSystem>();
19         }
20
21
22         
private void OnParticleCollision(GameObject other)
23         {
24             
int safeLength = m_ParticleSystem.GetSafeCollisionEventSize();
25
26             
if (m_CollisionEvents.Length < safeLength)
27             {
28                 m_CollisionEvents =
new ParticleCollisionEvent[safeLength];
29             }
30
31             
int numCollisionEvents = m_ParticleSystem.GetCollisionEvents(other, m_CollisionEvents);
32             
int i = 0;
33
34             
while (i < numCollisionEvents)
35             {
36                 
if (Time.time > lastSoundTime + 0.2f)
37                 {
38                     lastSoundTime = Time.time;
39                 }
40
41                 
var col = m_CollisionEvents[i].colliderComponent;
42                 
var attachedRigidbody = col.GetComponent<Rigidbody>();
43                 
if (attachedRigidbody != null)
44                 {
45                     Vector3 vel = m_CollisionEvents[i].velocity;
46                     attachedRigidbody.AddForce(vel*force, ForceMode.Impulse);
47                 }
48
49                 other.BroadcastMessage(
"Extinguish", SendMessageOptions.DontRequireReceiver);
50
51                 i++;
52             }
53         }
54     }
55 }