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.
50 lines
1.4 KiB
50 lines
1.4 KiB
3 years ago
|
using System;
|
||
|
using UnityEngine;
|
||
|
using System.Collections.Generic;
|
||
|
|
||
|
namespace UnityStandardAssets.Effects
|
||
|
{
|
||
|
public class WaterHoseParticles : MonoBehaviour
|
||
|
{
|
||
|
public static float lastSoundTime;
|
||
|
public float force = 1;
|
||
|
|
||
|
|
||
|
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);
|
||
|
int i = 0;
|
||
|
|
||
|
while (i < numCollisionEvents)
|
||
|
{
|
||
|
if (Time.time > lastSoundTime + 0.2f)
|
||
|
{
|
||
|
lastSoundTime = Time.time;
|
||
|
}
|
||
|
|
||
|
var col = m_CollisionEvents[i].colliderComponent;
|
||
|
var attachedRigidbody = col.GetComponent<Rigidbody>();
|
||
|
if (attachedRigidbody != null)
|
||
|
{
|
||
|
Vector3 vel = m_CollisionEvents[i].velocity;
|
||
|
attachedRigidbody.AddForce(vel*force, ForceMode.Impulse);
|
||
|
}
|
||
|
|
||
|
other.BroadcastMessage("Extinguish", SendMessageOptions.DontRequireReceiver);
|
||
|
|
||
|
i++;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|