- Home /
Particle Effects Script
How would I got about writing a script which would play a particle effect of a blood splatter when my bullet prefab hits something with a tag called enemy and plays an explosion particle effect if it hits something without a tag called enemy?
Answer by kevork · Oct 14, 2011 at 04:55 PM
In a script attached to your bullet prefab in OnCollisionEnter() check the tag of the object you hit to spawn the appropriate effect.
void OnCollisionEnter(Collision collision)
{
if(collision.gameObject.CompareTag("enemy"))
// trigger the blood splatter effect
else
// trigger the explosion effect
}
For creating the effects, I'd start with the Unity Particle System.
I have an errors saying, "unexpected token: else" any ideas?
Yea, you need to replace "// trigger the blood splatter effect" with something that does what the comment specifies. Exactly what to replace it with depends on how you create the effect that you want to play.
Look up how to spawn and create spawnables in Unity. $$anonymous$$ost popular page is: http://unity3d.com/support/documentation/$$anonymous$$anual/Instantiating Prefabs.html
(in the User $$anonymous$$anual)
Creating "blood" should look a lot like the way your bullets are being Instantiated (spawned/created.)
Your answer
![](https://koobas.hobune.stream/wayback/20220613010646im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Particle Effect Script Help 1 Answer
Another Scripting Question 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
A node in a childnode? 1 Answer
C# SphereCast isn't Inaccurate 1 Answer