Stop a particle effect after spawn (or certain amount of time)

I haven’t done any work with spawning in Unity, was wondering how you can get a particle effect to play briefly upon an object appearing (in C#). Think about in Banjo Kazooie when you enter a new level and magic sparkles surround you for a brief moment, or in any FPS where a brief flashing effect happens upon teleporting or spawning.
I can call ParticleSystem.Play() and then instantiate the object, but how can I get it to stop about half a second after the object appears in the world?

Save a reference to your particle system when you instantiate it and the after whatever time call ParticleSystem.Stop() or destroy it, depending on what you want.

Now you can count the time using coroutine. Start a coroutine, call yield return new WaitForSeconds(time) and after that stop the particle system in whatever way you see fit. Example code:

void SpawnParticleSystem()
	ParticleSystem particleSystem = Instantiate(prefab).GetComponent<ParticleSystem>();
	StartCoroutine(StopParticleSystem(particleSystem, 1));

IEnumerator StopParticleSystem(ParticleSystem particleSystem, float time)
	yield return new WaitForSeconds(time);

Simply turn off Loop, and set a short Duration. Both settings are available in the Main Module. Or just do it in the Inspector.