Hi, I found this Question from 2015 Can you change the speed of a spawned particle?
Is this stll true?
And what would be a way around that because i really need to change the speed of the whole particle systhem from script !
Changing values of newly created particles:
Get ParticleSystem.MainModule
from ParticleSystem
to access those values:
public ParticleSystem ps;
ps = GetComponent<ParticleSystem>();
ParticleSystem.MainModule main = ps.main;
main.startSpeed = 6;
Note that this is only available starting from Unity 5.5.
Docs: Unity - Scripting API: MainModule
Changing values of existing particles:
Get the particles first by ParticleSystem.GetParticles
, modify those values, then set it back again by ParticleSystem.SetParticles
:
ParticleSystem ps;
int particleCount = ps.particleCount;
ParticleSystem.Particle[] particles = new ParticleSystem.Particle[particleCount];
ps.GetParticles(particles);
for (int i = 0; i < particles.Length; i++)
{
particles_.velocity *= 2f;_
}
ps.SetParticles(particles, particleCount);
Docs: Unity - Scripting API: ParticleSystem.GetParticles
Unity - Scripting API: ParticleSystem.SetParticles
So your answer was great @NightFox , but i ended up using the Simulation Speed from main, because it effectively changes both the Velocity and the startSpeed of all particles while maintaining the Lenght and overall shape of the PS, using less precios cpu Time, and being easyer to implement.
The only downside is that stuff like the trail lenght of particles stayes the same, But for that detail I don’t want to go down the rabbithole of changing every single parameter to keep the look of the PS the same.
SO my function ended up being as simple as this :
public void ParticleSpeed (ParticleSystem ps, float defaultVelocity, float VelocityMultiplyer){
ParticleSystem.MainModule main = ps.main;
main.simulationSpeed = defaultVelocity * VelocityMultiplyer;
Debug.Log ("Particle simSpeed : " + main.simulationSpeed);
}
but thanks again for your Answer.