Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[noob] Get Textures/Materials from Project Library by script

Discussion in 'Scripting' started by Herbert West, Apr 6, 2009.

  1. Herbert West

    Herbert West

    Joined:
    Mar 28, 2009
    Posts:
    12
    hi,

    I've stored materials and textures in the "Project" panel

    But i don't want to drag and drop them on scene objects with polygons, I want to apply them on a empty gameObject whose mesh has been generated by script

    So i need to access the texture or the shader stored in the project panel with script, but i can't find the method to access these objects
     
  2. Maker16

    Maker16

    Joined:
    Mar 4, 2009
    Posts:
    779
    I had a similar issue with loading textures programatically for GUI elements. What I came up with is Resources.Load("filename"). Don't incude the extension. This requires you to have a Resources folder somewhere in your assets folder, and all the textures within it. I'm sure there is a better way to do it, but this is what worked for me. Have no idea about shaders, though.
     
  3. Herbert West

    Herbert West

    Joined:
    Mar 28, 2009
    Posts:
    12
    thank u much... it's ok for a small game

    i found how to do it with downloaded textures too (using WWW and Texture2D classes)

    and i suppose for an offline projector i can do it with c# IO package


    about shader i suppose they can be created with script