Question by
SmokiestSpace6 · Mar 28, 2019 at 02:21 AM ·
raycastraycasthitinfinitewhilewhile loop
Raycast.distance not working in a while loop
I have a character that I want to roam hallways, and I want it to turn until the raycast hits something more than 20 units away, but when I say -
if (Physics.Raycast(transform.position, Vector3.forward, out hit)) { while (hit.distance < 20) { transform.eulerAngles = new Vector3(0, transform.eulerAngles.y + 10, 0); } }
The game doesn't run, like it's stuck in a loop, but I'm not sure how to get around that, any ideas? Thanks
Comment