Removing runtime array exception (C#)
I have this code which makes the player (car) bounce off walls by rotating it 180 degrees, but whenever it should set wall to false, it does so, but it also spams an array OutOfRangeException. How do i remove this?
The code doesn't seem to want to display correctly, so here's a pastebin link: http://pastebin.com/uz9zgPDz
It's the code in the if statement that is causing the problem, because it cannot access the 0th entry of the array, when the array is empty
Answer by ARKMs · Nov 06, 2015 at 06:57 AM
First you should check if there is at least a contact:
Collider[] hitColliders = Physics.OverlapSphere(transform.position, range, wallLayer);
if (hitColliders.Lenght > 0 && hitColliders[0] != null)
Your answer
Follow this Question
Related Questions
3D Player Controller Movement won't face it's head in the direction of the arrow key press 0 Answers
How To Make An Object Appear In Front Of Player Without Cloning? 1 Answer
How do you rotate the player and keep them there? 1 Answer
IndexOutOfRangeException error when getting transform of array object 0 Answers
How to fix snake behavior in Unity3d? 0 Answers