- Home /
Object creation in Update
Hi, I am new to Unity and messing with some concepts. I'm bit confused about creating objects in Update()
function. I wrote a simple code where I used conditional statement to create a vector2 object and next frame the condition stop working. Even though the condition stop working but the rigidbody.velocity
is still updating. What I assume is that, during first frame new Vector2
object is created and after first frame it keeps updating the value through the object not the Update() Am I right?
Here's the code.
bool a = true;
void Update()
{
if (a)
{
Debug.Log("Velocity");
rigidbody.velocity = new Vector2(1,0);
a = false;
}
}
Answer by jihadkhawaja · Jul 28, 2021 at 01:10 AM
Hey there, Since ur using velocity instead of adding force, you should set the velocity back to Vector2.zero to stop it when it’s false
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Finding object in update function not working. 0 Answers
Best way to spawn new objects that arent already in the scene? 1 Answer