Please learn how to debug your own code first. Don’t ask users on the forum until you’ve tried yourself. If you have done this then that’s great(!) but please post those results rather than a stack-dump and a bit of code without any explanation. Anything else is just low effort .
The error is pretty clear telling you that you’re accessing an index of an array that is out of bounds and even exactly where in your code. Nobody here can debug it in their heads, only spot gross coding mistakes and often that isn’t the reason why it’s failing.
NOTE: I moved this from the 2D forum as it’s not related to 2D but generic C# scripting.
Thanks.