- Home /
Rigidbody load problem
I have a script:
var boxprefab : Rigidbody; function Update () { if (Input.GetKey("up")) { Instantiate(boxprefab, transform.position, transform.rotation); } if (Input.GetKey("space")) { Instantiate(boxprefab, (transform.position), transform.rotation);
}
}
but when i press space or up it creates the Rigidbody for a bit and the game starts to lag and not receive any key presses until the Rigidbodys have deleted themselves. How can i make it so that it doesn't lag?
Answer by Eric5h5 · Dec 19, 2010 at 08:42 PM
Use GetKeyDown so you only instantiate once, not every frame.
Is there any way to stop the lag without slowing the creation rate of the creation of the Rigidbodies?
You really don't want to make one every frame, because that means it's framerate-dependent, which is bad. Use InvokeRepeating or a timer or something, but keep in $$anonymous$$d that lots of objects = lag, no matter what. The CPU can only do so much.
is there a function that will make an object instantiate a certain amount of time each second?
Your answer
![](https://koobas.hobune.stream/wayback/20220613091701im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Changing speed and rotation of a rigidbody gets bugy 2 Answers
How can I instantiate rigid bodies on top of each other without them exploding away? 2 Answers
How to make an object without Rigidbody move at the same speed as an object with Rigidbody? 1 Answer
How Do I Increase the ForwardForce of the player over time? using rigid body 2 Answers
OnCollisionEnter not being called, between a Rigidbody and a Box Collider 1 Answer