Quantcast
Channel: Questions in topic: "error message"
Viewing all articles
Browse latest Browse all 2891

IndexOutOfRangeException help on debug

$
0
0
I'm hitting a IndexOutOfRangeException error on one line of my code and it's driving me crazy! The code itself works and I know why I'm gave the error but don't know how to fix (it's really annoying have the error popup everytime I execute the code). The part of code is: public void NextOnMouth() { if (imageNumber <= mouthImages.Length -1) { imageNumber++; finalImage.sprite = mouthImages[imageNumber]; } } the error is on the line: finalImage.sprite = mouthImages[imageNumber]; On the update I call another bit of code that says if imageNumber(int) is bigger than the lenght of the object array, the value of it is 0 and it updates the sprite again. if (imageNumber >= mouthImages.Length && mouth) { imageNumber = 0; finalImage.sprite = mouthImages[imageNumber]; } The error says to me that i'm trying to access the index that is out of the array (but the exact frame its out I reset it to zero, so i try to access a value that I already modified. The code works but I don't like errors on my console. Any thoughts?

Viewing all articles
Browse latest Browse all 2891

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>