Setting the Mesh of a particle system during runtime
How would I go about getting the mesh filter of a particle collision and than assign that mesh to the particle.
So I have a OnParticleCollision. I hit the object take this object I get its Mesh Filter. I than want to assign this to that of my particle so it takes the effect of its physical build.
This is during runtime.
Here is my code so far.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class LightingGun : MonoBehaviour { // Start is called before the first frame update public ParticleSystem part; public ParticleSystem ElectricWave; public List collisionEvents;
void Start()
{
Debug.Log("Script Starting...");
part = GetComponent<ParticleSystem>();
collisionEvents = new List<ParticleCollisionEvent>();
}
void OnParticleCollision(GameObject coll)
{
// Getting the object of the collider
Collider obj = coll.GetComponent<Collider>();
Mesh mesh = obj.GetComponent<MeshFilter>().mesh;
// Assign the mesh shape of the collider to that of the particle
ElectricWave.shape.meshRenderer = mesh; // I know this doesnt work as is.
// Play effect
ElectricWave.Play();
}
// Update is called once per frame
void Update()
{
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612224124im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Particle System Prefab on collision? 0 Answers
changing the radius of a particle system with unity script 1 Answer
Is there a way to detect particle collision on rigidbody trigger collider? 0 Answers
While particle system is alive play animation. 0 Answers
Can I shoot a ray from a particle that hit a collider? 1 Answer