Play and Stop
- Game Development course
- Intermediate
- Lesson 41/83
- 4 min
Learn to control particles with particleSystem.Play and Stop.
Playback Control with Play and Stop
Particle systems are controlled from C# code using the Play() and Stop() methods. When a character jumps, you call ps.Play() to emit dust, and when shooting stops, you call ps.Stop() to halt muzzle smoke.
ParticleSystem ps = GetComponent<ParticleSystem>();
ps.Play();
// ps.Stop();isPlaying and State Checks
To determine if a particle system is actively running, check the ps.isPlaying boolean property. Additionally, when calling Stop(), behavior parameters let you decide whether existing particles disappear immediately or finish their lifespan.
if (ps.isPlaying)
{
Debug.Log("Effect is currently playing.");
}Practice Play and Check Effect
Call ps.Play();. Then if ps.isPlaying is true, print Debug.Log("Efekt calisiyor");.
Starter code
using System;
public class ParticleSystem
{
public bool isPlaying = false;
public void Play() { isPlaying = true; }
public void Stop() { isPlaying = false; }
}
public static class Debug
{
public static void Log(object message) => Console.WriteLine(message);
}
public class Program
{
public static void Main()
{
ParticleSystem ps = new ParticleSystem();
// Oynat ve calisiyorsa ekrana mesaj yazdir
}
}Sample solution
using System;
public class ParticleSystem
{
public bool isPlaying = false;
public void Play() { isPlaying = true; }
public void Stop() { isPlaying = false; }
}
public static class Debug
{
public static void Log(object message) => Console.WriteLine(message);
}
public class Program
{
public static void Main()
{
ParticleSystem ps = new ParticleSystem();
ps.Play();
if (ps.isPlaying)
{
Debug.Log("Efekt calisiyor");
}
}
}Expected output
Efekt calisiyor
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which method is called to stop an active Particle System effect from code?
- ps.Destroy()
- ps.Stop() Correct answer
- ps.Disable()
- ps.Pause()
Explanation: The Stop() method is called to stop a ParticleSystem.
2 Play Particle
particleSystem.____();
particleSystem.Play();
Explanation: To launch the particle effect, the Play() function is called.
3 Control Methods and Properties
| Term | Meaning |
|---|---|
ps.Play() |
Starts playing the particle effect |
ps.Stop() |
Stops emitting new particles |
ps.isPlaying |
Shows if particle system is playing |
ps.Clear() |
Clears all particles in the scene |