Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Using spiresheet in c# code

Discussion in 'General Graphics' started by whistler, Dec 17, 2014.

  1. whistler

    whistler

    Joined:
    Apr 15, 2013
    Posts:
    15
    Hi,

    I have some public variables, like this code below:

    public Texture2D myImage;

    I put all my graphics in a spritesheet atlas, sliced them and want to use one of those sprites in my C# code. But I cant use them since my variable is Texture2D.

    Is there a way to use SpriteSheet images as Texture2D ?
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Why don't you use

    Code (csharp):
    1. public Sprite myImage;
    ?

    --Eric
     
  3. whistler

    whistler

    Joined:
    Apr 15, 2013
    Posts:
    15
    can't :(
    want to use that sprite it on GUI.DrawTexture (which only takes Texure2D to draw)
    wish we got smt like GUI.DrawSprite.
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can use GUI.DrawTextureWithTexCoords.

    --Eric