Search Unity

Loading an external textue from C# script

Discussion in 'Scripting' started by Andre Gregoire, Sep 2, 2009.

  1. Andre Gregoire

    Andre Gregoire

    Joined:
    Aug 28, 2009
    Posts:
    32
    How can i load an image from my Asset folder in a C# script i tried:

    Code (csharp):
    1. Texture2D icon=Resources.Load("Image_projet1a.jpg") as Texture2D;
    but the image does not show up...

    Anyone has any idea?
     
  2. Murcho

    Murcho

    Joined:
    Mar 2, 2009
    Posts:
    309
    Make sure the file is inside a folder named Resources inside your assets folder.
    e.g.
    Code (csharp):
    1.  
    2. ProjectName/Assets/Resources
    Also if you place it inside another folder inside Resources, you need to give the absolute path starting from resources.
    Code (csharp):
    1.  
    2. // If the file is in ProjectName/Assets/Resources/Textures you would call the load like this
    3. Texture2D icon=Resources.Load("Textures/Image_projet1a.jpg") as Texture2D;
    4.