Question by
anthonybentson · Jan 18, 2020 at 08:53 AM ·
instantiatetriggertag
Help spawning particle systems on collision enter
Hey guys, I've just started working on a blood script that would spawn a Particle System when it detected a collision. I first started with it spawning as soon as anything ran into the spawn point, but this causes issues with unwanted collisions and all that. I decided to try and get it to spawn when the collider thats colliding with the BloodSpawn point had the tag AttackPoint and if it did and the recieving collider had the BloodSpawn tag, it would spawn the effect. Here's my code:
public class Blood : MonoBehaviour
{
public GameObject bloodEffect;
// Update is called once per frame
void OnTriggerEnter2D(Collider2D receiving)
{
if (tag == "AttackPoint") //check if the colliding collider has the attack point tag
{
if (receiving.tag == "BloodSpawn") //if the colliding collider has attack point, check if recieving collider has the blood spawn tag
{
Instantiate(bloodEffect, transform.position, transform.rotation); //spawn blood at the object with bloodspawn tag
}
}
}
}
I'm still fairly new, so thanks for all the help!
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612221725im_/https://answers.unity.com/themes/thub/images/avi.jpg)