Change sprite collection
HI! I need to change a sprite, but this is in another collection i found this:
var obj =Instantiate(prefab, new Vector3(0,0,-i),Quaternion.identity);
((Transform)obj).GetComponent<tk2dSprite> ().Collection.name = ("Collection2");
But it doesnt work u.u im using :
((Transform)obj).GetComponent<tk2dSprite> ().SetSprite ("bg" + i);
For change the sprite and it works.
So, i just need to know how to change the sprite collection. Im using 2D toolkit Unity Ver 5.13 C#scripts
Comment
Best Answer
Answer by jjjulio · Feb 23, 2016 at 10:39 PM
using UnityEngine; using System.Collections;
public class MySprite : MonoBehaviour {
public tk2dSpriteCollectionData[] collections;//you'll need to import the collections you need directly from unity editor
// Use this for initialization
void Start () {
GetComponent<tk2dSlicedSprite> ().Collection = collections[1];//index of collections array
}
}
//it worked for me
;)