How to read textures from texture atlas

Hi everyone,

In my 2Dproject I have a spritesheet with a number of textures and I want to add a texture to my buttons that is placed on my spritesheet. What script do I have to use to add one of the textures from the spritesheet to my button ?

Thanks in advance

Import the texture as sprite and select as multiple. Later you can use sprite packer to select individual sprites. When done every sprite will appear as a individual one the project folder

Is that a better option than importing just the spritesheet and retrieving the images by getting the sprite.rect values ?

When I searched I found out you can either import the images separately and get them together in unity using spritepacker or you can just make a spritesheet in texturepacker or another program and import the spritesheet into your project.

For anyone reading this what do you prefer ? Importing textures separately and packing then together in unity or just importing the spritesheet ?

This is what I have but “Array.IndexOf” is flagged in red. the error message says; The name `Array’ does not exist in the current context.

        Sprite[] textures = Resources.LoadAll<Sprite>(" spritesheetT");
        string[] names = new string[textures.Length];

        for(int ii=0; ii< names.Length; ii++) {
            names[ii] = textures[ii].name;
        }

        Sprite sprite = textures[Array.IndexOf(names, " number4")];

do you have the following at the top of your script?

using System;

Thanks that worked. How can I display the single image “number4” because right now it still plays the whole animation on the spritesheet. What I want virtools to do is just display a single image from my spritesheet.