- Home /
Access gravity modifier in the particle system by Script (C#)
So i have been looking around the forum for an answer but i can't really quite get the answer i need. what i want to do is change to value of the gravity modifier in my particle systemen. I tried using multiple metods like "GetComponent" but that does not give me the option to choose the gravity modifier option. so i do not really know how i should solve this problem. I hope some you you guys here that are more experienced in this area might have the answer.
Answer by andrew-lukasik · Jan 24, 2016 at 06:13 PM
Use GetComponent only when you can't fill object reference field by hand. And here are great learning materials you probably need and will gain from greatly. Also, make sure you're programming in Monodevelop and not notepad since mono will help you providing handsome amount of hints vital for learning all this stuff.
//C#
public ParticleSystem particleSystemComponent = null;
public float gravity = 2f;
void Awake () {
if( particleSystemComponent==null ){
Debug.LogError( "Oh noes! You forgot to fill particleSystemComponent field in inspector here" );
Debug.Break();
return;
}
particleSystemComponent.gravityModifier = gravity;
}
Thanks This was exactly What i needed! It works great now. Tanks for the other tips as well, they where useful!
Your answer
![](https://koobas.hobune.stream/wayback/20220612061516im_/https://answers.unity.com/themes/thub/images/avi.jpg)