I have 2d prefab falling down with gravity. I want to increase falling speed of them randomly in runtime.
How can I do this in correct way? Changing Gravity Scale in runtime does make sense?
I have 2d prefab falling down with gravity. I want to increase falling speed of them randomly in runtime.
How can I do this in correct way? Changing Gravity Scale in runtime does make sense?
Add a script to the prefab.
I’m using C#.
Script.cs:
gameObject.transform.position.y-=Random.Range(minspeed,maxspeed);
gameObject.transform.position.y
accesses the prefab’s y position, and decrease it randomly in a predefined range using Random.Range(minspeed,maxspeed);
The minimum speed and maximum speeds are both floats, so you have to add the letter F after the value.