Can’t seem to find the issue… I have checked all of my gameobjects and my script is only on one of them. The error I’m getting is:
IndexOutOfRangeException: Array index is out of range.
SelectCharacter.Update () (at Assets/Scripts/SelectCharacter.cs:17)
This is the main script
using UnityEngine;
using System.Collections;
public class SelectCharacter : MonoBehaviour {
public static int chickenSelect;
public bool rainbowUnlocked;
public bool halloweenUnlocked;
public SpriteRenderer Chicken;
public Sprite[] chickenSprite;
void Start(){
chickenSelect = 0;
}
void Update(){
Chicken.sprite = chickenSprite [chickenSelect];
if(chickenSelect > chickenSprite.Length){
chickenSelect = 0;
}
if (chickenSelect < chickenSprite.Length) {
chickenSelect = chickenSprite.Length;
}
}
}
Then I have some scripts on my arrow buttons:
using UnityEngine;
using System.Collections;
public class RightArrow : MonoBehaviour {
void OnMouseDown(){
SelectCharacter.chickenSelect++;
}
}
and left one
using UnityEngine;
using System.Collections;
public class LeftArrow : MonoBehaviour {
void OnMouseDown(){
SelectCharacter.chickenSelect--;
}
}
If anyone knows why I am gettting the error it would be very helpful.