Performance: Visual effect examples (fire, smoke, sparkle)
This affects the rendering performance and frame rate by how many particles and shaders are used in visual effects.
Jump into concepts and practice - no test required
var ps = gameObject.AddComponent<ParticleSystem>(); var main = ps.main; main.maxParticles = 500; // Use simple additive shader var emission = ps.emission; emission.rateOverTime = 50; // Enable particle culling and LOD
var ps = gameObject.AddComponent<ParticleSystem>(); var main = ps.main; main.maxParticles = 10000; // Using complex shaders and high emission rate var emission = ps.emission; emission.rateOverTime = 1000; // No culling or LOD
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| High particle count with complex shaders | N/A | N/A | High GPU draw calls and shader cost | [X] Bad |
| Optimized particle count with simple shaders | N/A | N/A | Low GPU draw calls and simple shader cost | [OK] Good |
fireEffect?Play() on the ParticleSystem starts the effect. So fireEffect.GetComponent<ParticleSystem>().Play(); is correct.using UnityEngine;
public class SparkleEffect : MonoBehaviour {
void Start() {
var ps = GetComponent<ParticleSystem>();
ps.Stop();
ps.Play();
Debug.Log(ps.isPlaying);
}
}ps.isPlaying returns true, so the Debug.Log prints true.using UnityEngine;
public class SmokeEffect : MonoBehaviour {
ParticleSystem smoke;
void Start() {
smoke.Play();
}
void Awake() {
smoke = GetComponent<ParticleSystem>();
}
}sparkleEffect.GetComponent<ParticleSystem>().Play() inside the coin collection method starts the effect correctly.