- Home /
how to select/change which sprite set is used from a multiple set spritesheet?
how to select/change which sprite set is used from a multiple set spritesheet?
game simple : http://www.youtube.com/watch?v=aGqTo61tE4I
FTR just use 2DToolkit (asset store) and the job is totally done
Answer by progamerpagan819 · Jan 15 at 11:23 PM
This is what works for me in this scenario. This way you can get all the Sprites inside the single Texture., First, you will need to get a "Resource" folder inside the "Asset" folder (Note: Anything within the Resource folder can be gathered within the script). Here is an example using
public class CursorScript : MonoBehaviour
{
private SpriteRenderer spriteRender;
private Sprite[] renderToSprite;
// Start is called before the first frame update
void Start()
{
//Get the "SpriteRender Component to modified the image of the cursor.
spriteRender = gameObject.GetComponent<SpriteRenderer>();
//Set the name of the Image Sprite.
string multiSpriteName = spriteRender.sprite.texture.name;
//Set the location A.K.A the path of where the multi-Sprite Image is located
(Note: The image has to be inside the "Resource" Folder).
string path = "Sprites/UI/";
//Get all Sprites that fit the requirements to cast into the "RenderToSprite".
renderToSprite = Resources.LoadAll<Sprite>(path + multiSpriteName);
//Render a new sprite selected in the "renderToSprite[Array]".
spriteRender.sprite = renderToSprite[1];
}
}
This is what works for me in this scenario. This way you can get all the Sprites inside the single Texture.
Your answer

Follow this Question
Related Questions
Change Character Controller Collider - to another Collider? (*CCCC+Quest*) 1 Answer
How do I change my speed based on certain events? 0 Answers
How to change part of complex gameobject instantiated from prefab? 1 Answer
SetCursor WebGL doesn't work 1 Answer
change scene on click of a 3d object 1 Answer