Home > Blockchain >  Magnitude with ParticleSystem (enabled/disabled) not working
Magnitude with ParticleSystem (enabled/disabled) not working

Time:03-19

I'm just learning unity3d. I need to show particles every time the speed of the object exceeds 6km. The problem is that it doesn't always work, and it doesn't work in the right way. Why does this happen and how to fix it? The problem itself starts after the first interruption. Code Example:

{
   float currentSpeed = Mathf.Abs(Rigidbody.velocity.magnitude);

   //Bad show hide particles (It works every once in a while)
   particleSystem.enableEmission = (currentSpeed >= 6) ? false : true;
}

For some reason, the particles are shown in a certain place but not always. When the speed in print(currentSpeed) exceeds it is not always shown. (Only the first iteration works correctly).

I've noticed that it appears in certain places on the map at 6kms, and experience has not yet allowed me to determine why this is happening.

CodePudding user response:

I think you have confused yourself by using a conditional operator. If the condition is true, the first option will be used.

particleSystem.enableEmission = (currentSpeed >= 6) ? false : true;

will only enable particles when the speed is below 6. Easier and giving the result you want is the following

particleSystem.enableEmission = currentSpeed >= 6;

if you would really like to write out the boolean values:

// redundant true/false
particleSystem.enableEmission = (currentSpeed >= 6) ? true : false;
  • Related