Found this answer for the exact same thing I am wanting to do, instantiate a prefab sprite sheet explosion at the OnParticleCollision(). I am trying to get the position of the collision position. My question with this… is this answer still the best method to do this being 3 years old now?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class instanciarEnColissionPatrticle : MonoBehaviour
{
public GameObject prefab;
public ParticleSystem Particulas;
public List collisionEvents = new List();
ParticleSystem _particleSystem;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
void OnParticleCollision(GameObject other)
{
// ParticleSystem part = other.GetComponent(); // *** important! Making a variable to acess the particle system of the emmiting object, in this case, the lasers from my player ship.
int numCollisionEvents = Particulas.GetCollisionEvents(this.gameObject, collisionEvents);
foreach (ParticleCollisionEvent collisionEvent in collisionEvents) // for each collision, do the following:
{
Vector3 pos = collisionEvent.intersection; // the point of intersection between the particle and the enemy
Instantiate(prefab, pos, Quaternion.identity);
// GameObject vfx = Instantiate(enemyHitVFX, pos, Quaternion.identity); // creating the explosion effect.
// vfx.transform.parent = parentGameobject.transform; // this makes the new gameobjects children to my “VFX Parent” gameObject in my Hierarchy, for organizarion purposes
}