Hi @jddg5wa,
Thank you for providing the extra information.
Since I can't upgrade to 5.5 right now to provide specific help, I'll give you an alternative solution.
This will work if the particleSystems are not stopped and played by other scripts.
Attach the following script to the tank object:
using UnityEngine;
using System.Collections;
public class TankParticlesExample : MonoBehaviour {
public ParticleSystem m_leftDustTrail;
public ParticleSystem m_rightDustTrail;
private Rigidbody m_rigidBody;
void Start ()
{
m_rigidBody = GetComponent();
if (m_leftDustTrail == null)
{
Debug.LogError( "Don't forget to assign the LeftDustTrail in the inspector." );
}
if( m_rightDustTrail == null )
{
Debug.LogError( "Don't forget to assign the RightDustTrail in the inspector." );
}
}
void Update()
{
// If velocity is greater than 0.5f, show particles, else, don't.
if( m_rigidBody.velocity.magnitude > 0.5f)
{
_updateParticleSystem( m_leftDustTrail, true );
_updateParticleSystem( m_rightDustTrail, true );
}
else
{
_updateParticleSystem( m_leftDustTrail, false );
_updateParticleSystem( m_rightDustTrail, false );
}
}
private void _updateParticleSystem( ParticleSystem particleSystem, bool shouldBePlaying )
{
if ( particleSystem.isPlaying && !shouldBePlaying )
{
// Stop if currently playing and it shouldn't be.
particleSystem.Stop();
}
else if ( !particleSystem.isPlaying && shouldBePlaying )
{
// Play if currently not playing and it should be.
particleSystem.Play();
}
}
}
Make sure to assign the ParticleSystems in the inspector, just drag and drop.
Right now you have **Rate over Distance** set to 10, set that to 0.
And set **Rate over Time to 10**.
Also, **set Play on Awake to false.**
**Do this for both dustTrail Particle Systems.**
That should make it all work nicely. You can adjust the value of 0.5f to your needs, a higher value would require a greater speed before showing dust trails.
If it doesn't work, the Particle Systems are probably set to play and stop by other scripts.
In that case you can remove the particle systems (temporarily) to find out where that happens, because if you remove them and run the game, you should get an error. Double clicking on that error will lead you to its origin.
With that, you should be able to get it to work.
I hope this fulfills your request.
If this helped, please accept my answer, it'd be much appreciated!
If you need more details, let me know!
Best of luck!
Cheers,
ThePersister
↧