Seven is the number.
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.

49 lines
1.4 KiB

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