- Home /
The question is answered, right answer was accepted
How can I make fatal particles? (C#)
Hi, so I've come into a bit of a dead end here, I've spent a few hours working on a cannon, that has a Particle System in front of it, firing a single cannonball every second. The thing is, I'd like the cannonball to kill the player, right now they just bounce off the player. I've made a Tag for all things that are supposed to 'kill' the player, called "Fatal". Now, Could I somehow detect a collision with the particles, and kill the player, instead of having the cannonballs go absolutely crazy and fly into another universe? I've configured the game so that every object that the player collides with, and has the tag "Fatal", kills the player. Here's the tag code...
//Death Script, Tag Enemies and Objects with the tag "Fatal" in order for this to work!
void OnCollisionEnter(Collision other)
{
if (other.transform.tag == "Fatal")
{
Die();
}
}
//In case the character should die, just write Die (); to initiate the death.
void Die()
{
Instantiate(DeathParticles, transform.position, Quaternion.identity);
transform.position = spawn;
}
If anyone could help me create a script that allows me to make the particles (cannonballs) "Fatal" aswell, that'd be amazing! I'm also open to suggestions on new ways of making the cannonballs kill the player. Thanks in advance!
You can actually use the Particle System to spawn any object you like. These objects can contain any scripts.
I used the particle system to spawn Enemy aliens that were ejected from the bottom of a moving spaceship. The enemies we fully functioning, starting in Ragdoll mode then springing in to action when they hit the floor :)
Of course, tanoshimi has the simpler answer
Answer by tanoshimi · Jun 20, 2014 at 07:52 PM
You need to use OnParticleCollision rather than OnCollisionEnter. http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnParticleCollision.html
Oh, thanks a lot! I'm pretty new to Unity and C#, but this helped a lot!