Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    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