- Home /
Question by
areFranz · May 10, 2014 at 11:40 AM ·
c#shurikenonparticlecollision
Shuriken OnParticleCollision SendCollisionMessage doesn't work completely
Hi, I have a Shuriken LASER ParticleSystem with the collision and the SendCollisionMessages enabled. So I need to shoot this laser towards asteroids (Rigidbodies) thet every 4 shoots ere destroyed. I found the script for the asteroid in the Unity Documentation, and it works:
using UnityEngine;
using System.Collections;
public class Example : MonoBehaviour {
private ParticleSystem.CollisionEvent[] collisionEvents = new ParticleSystem.CollisionEvent[16];
void OnParticleCollision(GameObject other) {
ParticleSystem particleSystem;
particleSystem = other.GetComponent<ParticleSystem>();
int safeLength = particleSystem.safeCollisionEventSize;
if (collisionEvents.Length < safeLength)
collisionEvents = new ParticleSystem.CollisionEvent[safeLength];
int numCollisionEvents = particleSystem.GetCollisionEvents(gameObject, collisionEvents);
int i = 0;
while (i < numCollisionEvents) {
if (gameObject.rigidbody) {
Vector3 pos = collisionEvents[i].intersection;
Vector3 force = collisionEvents[i].velocity * 10;
gameObject.rigidbody.AddForce(force);
}
i++;
}
}
}
This script adds a force to the asteroids and make them go away in opposite direction... When i change to this:
if (gameObject.rigidbody) {
Debug.Log ("collision");
gameObject.rigidbody.GetComponent<AsteroidsRotation>().ApplyDamage (1);
}
In the console i receive the collision debug (many at one time) but the ApplyDamage Function isn't called...
Is there a simpler way to do what i need? Or somethisng to change in my script?
Comment