Hello! I want to make a particle effect. The game I am making is a Flappy Bird like and I am trying to add that effect to my player which is the bird in the current situation.
What I want to happen is whenever I am press Space
button to jump I want to also see that particle effect play.
How do I do that?
Thanks!
Step 1
Find the documentation page for Particle System
and look for Public Methods
list there.
→ Unity - Scripting API: ParticleSystem
Any “Play” method or something like that? You bet!
→ Unity - Scripting API: ParticleSystem.Play
Stop
:
→ Unity - Scripting API: ParticleSystem.Stop
Also Emit
:
→ Unity - Scripting API: ParticleSystem.Emit
So it’s
[SerializeField] ParticleSystem _particleSystem;
void Start ()
{
_particleSystem.Play();
}
Step2: Play on key press
What you need is Input.GetKeyDown( KeyCode.____ )
→ Unity - Scripting API: Input.GetKeyDown
Step3: Combine steps 1 & 2
[SerializeField] ParticleSystem _particleSystem;
void Update()
{
if( Input.GetKeyDown(KeyCode.Space) )
{
_particleSystem.Stop();
_particleSystem.Play();
}
}