I am trying to make the Rigidbody rb move randomly. But somehow when I run this Code, the Unity gets stopped and does not react not all. So Debugging is out of the Option.
The only possible reason that this Code destroys everything is that while loop. Am I tracked in the while loop ?
Your while loopâs condition never becomes false, and so it never exits the while loop, causing unity to enter into an infinite loop and freeze. Also, thereâs no reason to use a loop there, as unless you want the object to teleport to the target point, you will want the movement to take place over several frames.
Just to add onto this a little bit. You check whether âstartPositionâ not equals âtargetPositionâ. But this can never happen, because âstartPositionâ never changes. Your ârb.transform.positionâ however does. You are looking for: csharp~~ ~~// if statement because like fire7side said: you want to move over several frames, // and not the entire distance in 1 frame if (rb.transform.position != targetPosition) { // move towards }~~ ~~