I have a prefab that is constantly spawning and falling downwards. How do I them start off slower and then have them drop down faster every 30 seconds?
I tried using a rigidbody, but nothing seems to be occurring other than changing the constant falling speed.
Increasing Drag in the Rigidbody component will start it out falling slower. Then you can either decrease the drag, or ad force to the rigidbody, or both.
If you want the speed to change every 30sec, you need to create a timer. Such as:
var time : float;
function Update() {
time += 1 * Time.deltaTime; //Increase the variable 'time' by 1, every seceond
if(time >= 30) {
//Increase Speed
time = 0;
}
}
This is assuming you are using JavaScript?
I am using JavaScript. Do I insert this into a text mesh or do I attach to the gameObject. I did both, but nothing seems to be happening. I'm only using the timer script.
Attach it to whatever you want to fall. And, the first part of code I posted will need to be put with the second part, where it says "//Increase Speed".
I'm receiving this error: There is no 'Rigidbody' attached to the "Star(Clone)" game object, but a script is trying to access it. You probably need to add a Rigidbody to the game object "Star(Clone)". Or your script needs to check if the component is attached before using it. And my game seems to be lagging.
private float time;
private float fallForce; //Start this at whatever speed or make it public so you can change it in the inspector
void FixedUpdate()
{
rigidbody.AddForce(0, fallForce, 0);
if(time > 30)
{
fallForce += 2f; //Every second after 30 secs will increase the fallForce by 2 or whatever number you use
}
time += 1;
}
I am using JavaScript. Do I insert this into a text mesh or do I attach to the gameObject. I did both, but nothing seems to be happening. I'm only using the timer script.
– ZypherAttach it to whatever you want to fall. And, the first part of code I posted will need to be put with the second part, where it says "//Increase Speed".
– LylekI'm receiving this error: There is no 'Rigidbody' attached to the "Star(Clone)" game object, but a script is trying to access it. You probably need to add a Rigidbody to the game object "Star(Clone)". Or your script needs to check if the component is attached before using it. And my game seems to be lagging.
– Zypher