I have a particle gameobject which plays when character moves and stops when character stops moving. I need this effect to be on pivot of character so i made it child of character and included in character animation.
The problem is that particle effect not playing via code or on editor. It doesn’t even give any errors. Why doesn’t it let me play it ? Can you help me ?
private void MoveEffect()
{
if (playerRB.velocity.magnitude > 1)
{
moveEffect.GetComponent<ParticleSystem>().Play();
}
if (playerRB.velocity.magnitude < 1)
{
moveEffect.GetComponent<ParticleSystem>().Stop();
}
}
I assume you placed this MoveEffect() method into Update() or FixedUpdate()? Otherwise nothing will be calling it.
Actually, where have you put this code? I figured you’d have it either on the player’s controller, or a controller for this particle system. But, you’re referencing both playerRB and moveEffect, as though this code was on some third controller.
Anyway, you should at least start by debugging the code to see if it gets to the different points you expect it to get to. Do that either by attaching the debugger, or by adding Debug.Log statements into MoveEffect, and into its conditions.
@dgoyette Thanks for reply… Character contains this script which has this code in Update method. I comment out these lines in if() method so i am able to play this particle effect manually on editor.
=> moveEffect.GetComponent().Play();
These codes blocks particle system to run for some reasons but i don’t know why…
I didn’t understand the reason exactly but i got it working by a tiny change in codes
I have added a bool about if it’s playing or not…
,
private void MoveEffect()
{
if (playerRB.velocity.magnitude >= 1 && !moveEffect.GetComponent<ParticleSystem>().isPlaying)
{
moveEffect.GetComponent<ParticleSystem>().Play();
}
if (playerRB.velocity.magnitude < 1 && moveEffect.GetComponent<ParticleSystem>().isPlaying)
{
moveEffect.GetComponent<ParticleSystem>().Stop();
}
}
Hmm. It might have been starting over every time you called Play(), and maybe the first frame of the particle system isn’t very noticeable. So, your fix seems reasonable.
1 Like