Question by
AnonymusX · Feb 13, 2018 at 10:07 AM ·
scripting problemerrorscaleparticle systemshape
How do I change the shape scale in the Particle System via script?
I don't know if I'm missing something or if it's an issue with the particle system, but when I try to change the shape scale in the particle system via script I get:"Cannot modify the return value of 'ParticleSystem.shape' because it is not a variable".
This is the code I'm using:
public class AspectRatioScript : MonoBehaviour{
void Awake(){
ParticleSystem stars = transform.Find("Stars").GetComponent<ParticleSystem>();
Camera gameCamera = gameObject.GetComponent<Camera>();
stars.shape.scale = new Vector3(2f, 1f, 1f);
}
}
cattura.png
(41.4 kB)
Comment
Best Answer
Answer by ifurkend · Feb 13, 2018 at 10:18 AM
https://docs.unity3d.com/ScriptReference/ParticleSystem-shape.html
You can’t take the shortcut. You need to define the struct of the Shape module first:
var sh = stars.shape;
sh.scale = new Vector3(2f, 1f, 1f);
Oh thanks. I've never noticed the 'var' part... it got me stuck for 3 days.