I am trying to set the starting rotation of a particle system via c# script so that the particles orientate with another object in the scene. My particle system 3d rotation is set as follows:
void UpdateParticleSystemRotation(Quaternion rotation)
{
if(this.gameObject.GetComponent<ParticleSystem>() != null)
{
var particleSystemMainModule = gameObject.GetComponent<ParticleSystem>().main;
particleSystemMainModule.startRotationX = new ParticleSystem.MinMaxCurve(rotation.eulerAngles.x);
particleSystemMainModule.startRotationY = new ParticleSystem.MinMaxCurve(rotation.eulerAngles.y);
particleSystemMainModule.startRotationZ = new ParticleSystem.MinMaxCurve(rotation.eulerAngles.z);
}
else
{
Debug.LogError("There was an error");
}
}
The rotation.eulerAngles.x/y/z values are coming through correctly, and by debugging in VS I can see that the values have been correctly assigned, as below:
However I observe that the particle system is not at all orientated with this X value, and the particle system is showing a completely different value:
You can see from the screenshots above that a value of 74.5f becomes 4274.2f by the time it hits the particle system.
I have double checked that the type expected by the ParticleSystem.MinMaxCurve constructor is a float. I cannot understand why this is happening.
I would be very grateful if someone would be able to provide some clarification on this.
Many thanks in advance.
I should add, rotation seems completely random for any given input value, it doesn't follow any obvious rhyme or rhythm.
I am using Unity 2017.2.0f3