OnParticleCollision is called when a particle hits a collider (legacy particle system only).
This can be used to apply damage to a game object when hit by particles. This message is sent to all scripts attached to the WorldParticleCollider and to the Collider that was hit. The message is only sent if you enable sendCollisionMessage in the inspector of the WorldParticleCollider.
// Applies a force to all rigid bodies that are hit by the particle.
function OnParticleCollision (other : GameObject) {
var body : Rigidbody = other.rigidbody;
if (body) {
var direction : Vector3 = other.transform.position - transform.position;
direction = direction.normalized;
body.AddForce (direction * 5);
}
}
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
void OnParticleCollision(GameObject other) {
Rigidbody body = other.rigidbody;
if (body) {
Vector3 direction = other.transform.position - transform.position;
direction = direction.normalized;
body.AddForce(direction * 5);
}
}
}
import UnityEngine
import System.Collections
class example(MonoBehaviour):
def OnParticleCollision(other as GameObject):
body as Rigidbody = other.rigidbody
if body:
direction as Vector3 = (other.transform.position - transform.position)
direction = direction.normalized
body.AddForce((direction * 5))