Question about logical flow of a script

What I’m trying to do is trigger the prefab FireWorks from the particles folder when a rigidbody enters a trigger area, which is a box with “is Trigger”. I am new to scripting, I’ve always been the modeler/animator. I’m not looking for specific code,I am looking for the logical flow of this example. I know I’ll need a script that is attached to the trigger area. I know I’ll need to somehow call on the particleEmitter component of FireWorks in that script to turn it on when the area is triggered. What I don’t understand is how this all fits together.

I understand that I’ll first start with a class

public class TriggerGoal : Monobehaviour

I’m guessing that in that class I’ll need a variable to save the info from the FireWorks particle emitter state. But I’m not sure how that works or if that’s how it is done.

I know I’ll need the functionality for the actual trigger

void OnTriggerEnter(Collider other)

But after that I am lost. I’ve really tried finding this on my own but most questions answered here basically assume you understand how things work together, I believe.

Detailed sequence:

1- Drag the Fireworks effect to the scene and position it where you want; uncheck its field Emit in the Inspector, or the fire work will keep exploding forever;

2- Attach the script below to the trigger object;

3- Select the trigger object, then in the Inspector click the field Fire Work in the component Trigger Goal: this allows selection of the Fireworks effect you’ve placed in scene;

Presto! It’s ready to play!

public class TriggerGoal : MonoBehaviour;{

  public ParticleEmitter fireWork; // this will appear as Fire Work in the Inspector 

  void OnTriggerEnter(Collider other){ 

NOTE: The Fireworks effect will explode whenever any rigidbody or CharacterController enters the trigger. If you want to fire the effect only when certain objects enter the trigger, you may compare other.tag to some specific tag:

  void OnTriggerEnter(Collider other){ 
    if (other.tag == "SomeTag"){ // only SomeTag tagged objects will work

Remeber to tag the objects accordingly, if you want to use this alternative.

To emit particle, you will need a reference of the particle system component. The easiest to do that is to declare the variable as public and of type ParticleSystem (ParticleEmitter if it’s not the new particle system). It’s going to look like that :

// the first letter of fireWork being a lower case is just a convention.
public ParticleSystem fireWork; 

Then, you need to detect th collision. When the physic engine detect a collision, it sends a message to the game object being collided. If its collider is a trigger, that message is OnTriggerEnter. By implementing that function, you can receive the message. Now you need to make the emitter emit. For the new system, it would be fireWork.Play(); For the old one, fireWork.emit = true or fireWork.Emit();