I have started working on a new game and I want to make letters from a sprite sheet that change given the letter or number I give it. I created a numbers only sprite sheet in Photoshop just to test it and imported it into Unity as a Sprite. Then in a script I did this:
public string currLetter;
public string lettersName;
Sprite[] lettersAll;
void Awake () {
lettersAll = Resources.LoadAll<Sprite> ("Textures/" + lettersName);
}
void Update () {
switch (currLetter) {
case "0":
gameObject.GetComponent<SpriteRenderer> ().sprite = lettersAll[0];
break;
case "0":
gameObject.GetComponent<SpriteRenderer> ().sprite = lettersAll[1];
break;
}
}
I am getting an error in the switch statement where if it's for example number 1, it says that the array index is out of range and when I set the lettersAll to public it had 0 sprites. What am I doing wrong ? I have been trying to fix this all day but nothing works :/
Update:
Image of Sprite Sheet:
Resources.LoadAll
is failing. You can prove this by doingDebug.Log(lettersAll .Length);
under theResources.LoadAll
function. Let me know the sult of that log. Also, what directory did you put the Textures? Also, select the Texture and put a picture of the Import Settings for it. – Programmer