I have a sliced sprite named Castillo (Spanish word for ‘Castle’). The slices have default names: Castillo_0, Castillo_1, etc.
I need the slices at runtime, so I have made a Resources folder and I have put the sprite ‘Castillo’ in it.
I have a ‘Director’ empty object with this script:
using UnityEngine;
using System.Collections;
public class Prueba : MonoBehaviour {
// Use this for initialization
void Start () {
GameObject prueba = new GameObject ("prueba");
SpriteRenderer renderer= prueba.AddComponent<SpriteRenderer> ();
renderer.sprite = Resources.Load<Sprite> ("Tiles/Castillo/Castillo_1");
}
}
The object ‘prueba’ (‘test’ in Spanish) is created, but no sprite is loaded. If I change the argument of the function Resource.Load
to "Tiles/Castillo"
, then Castillo_0
is loaded. But how can other tiles be accessed?