0
0
Unityframework~5 mins

Visual effect examples (fire, smoke, sparkle) in Unity

Choose your learning style9 modes available
Introduction

Visual effects make games look exciting and real. Fire, smoke, and sparkle effects add life and mood to scenes.

When you want to show a campfire burning in a game.
When you want smoke coming out of a chimney or explosion.
When you want sparkles to appear when a player collects a treasure.
When you want to add magic or fantasy effects to characters or objects.
Syntax
Unity
using UnityEngine;

public class SimpleEffect : MonoBehaviour
{
    public ParticleSystem effect;

    void Start()
    {
        effect.Play();
    }
}

Attach this script to a GameObject that has a ParticleSystem component.

Use the Play() method to start the effect.

Examples
This script plays a fire particle effect when the game starts.
Unity
using UnityEngine;

public class FireEffect : MonoBehaviour
{
    public ParticleSystem fire;

    void Start()
    {
        fire.Play();
    }
}
This script plays a smoke particle effect when the game starts.
Unity
using UnityEngine;

public class SmokeEffect : MonoBehaviour
{
    public ParticleSystem smoke;

    void Start()
    {
        smoke.Play();
    }
}
This script plays a sparkle particle effect when the game starts.
Unity
using UnityEngine;

public class SparkleEffect : MonoBehaviour
{
    public ParticleSystem sparkle;

    void Start()
    {
        sparkle.Play();
    }
}
Sample Program

This program plays fire, smoke, and sparkle effects all at once when the game starts. Attach this script to an empty GameObject and assign ParticleSystem components for each effect in the Unity Editor.

Unity
using UnityEngine;

public class VisualEffectsDemo : MonoBehaviour
{
    public ParticleSystem fireEffect;
    public ParticleSystem smokeEffect;
    public ParticleSystem sparkleEffect;

    void Start()
    {
        fireEffect.Play();
        smokeEffect.Play();
        sparkleEffect.Play();
    }
}
OutputSuccess
Important Notes

Make sure you have ParticleSystem components set up in your Unity scene for each effect.

You can customize the look of each effect by changing the ParticleSystem settings in the Unity Editor.

Use Stop() method to stop effects if needed.

Summary

Visual effects like fire, smoke, and sparkle use ParticleSystem in Unity.

Attach scripts to GameObjects and call Play() to start effects.

Customize effects in the Unity Editor for different looks.