Enabling particle system with trigger
I'm trying to make it so the particle system is enabled whilst the player is in the trigger, but I can't get the emission.enabled to work for me. I don't want to turn the whole game object on and off because I want the remaining particles to finish their cycle. Can anyone help?
using UnityEngine;
using System.Collections;
public class SparkleScript : MonoBehaviour {
public ParticleSystem Sparkle;
void Start () {
Sparkle.emission.enabled = false;
}
void OnTriggerEnter () {
Sparkle.emission.enabled = true;
}
void OnTriggerExit () {
Sparkle.emission.enabled = false;
}
}
Answer by AmirArdy · Mar 21, 2020 at 03:59 PM
hi charlottie333, maybe it's too late for answering this question. I hope you've found your answer by now. But here is a solution for the thing that you want to do:
public class EmitParticleTrigger : MonoBehaviour
{
public ParticleSystem particle;
public int emitCount;
private void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.tag == "Player")
particle.Emit(emitCount);
}
}
Here is documentation if you wanna know what Emit() is doing specifically: https://docs.unity3d.com/ScriptReference/ParticleSystem.html
Your answer
Follow this Question
Related Questions
How Play and Stop a ParticleSystem through Scripting? 9 Answers
Help with a door slam trap 0 Answers
ParticleSystem.Emit Deprecated? 1 Answer