x


C# Resources.Load() problem

I try to load image by script.

But I don't load image.

Is there any way to load a texture from a string reference?

code

public class LearningScript : MonoBehaviour

{

  private Texture testTexure; 
  void Start() 
  { 

       Object temp = Resources.Load("iPhone Standard Assets/Textures/sky_02"); 

       if (  temp == null ) 
          Debug.Log("Load Object Fail"); 

       testTexure = Resources.Load("iPhone Standard Assets/Textures/sky_02" ) as Texture; 

       if ( testTexure == null ) 
         Debug.Log("Load Texture Fail"); 
   } 

}

resource

alt text

result

alt text

more ▼

asked Apr 09, 2010 at 04:23 AM

Exotic Utopia gravatar image

Exotic Utopia
38 1 2 6

@Exotic, in addition to checkmarking the best answer (which you did), it's helpful to upvote good answers, not only here, but any others that you find useful or informative.

Apr 09, 2010 at 02:44 PM Cyclops

Cyclops: and upvoting requires 15 rep, which Exotic doesn't have yet.

Mar 24, 2011 at 11:57 AM Minthos
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

You can only load textures, models etc, by using Resources.Load if they are placed under a folder named "Resources" (see the scripting reference for more info). So if you move your sky_02 texture to a folder named "Resources" and change the "iPhone Standard Assets/Textures/sky_02" string to simply "sky_02" it should work.

more ▼

answered Apr 09, 2010 at 07:05 AM

TrolleFar gravatar image

TrolleFar
126 1 3 4

Thanks good answer.

Apr 09, 2010 at 07:33 AM Exotic Utopia

and note you can keep your resources organized in sub-folders and pass the relative path to Resources.Load, for example move sky02 to Resources/Textures and use Resources.Load("Textures/sky02").

Apr 25, 2010 at 06:42 PM yoyo

thanks for the answer. It wasnt a very obvious solution. I wouldnt discover that if i didint read this thread..

Dec 28, 2011 at 08:54 AM yigitcan

thanks that did helped me

Aug 16, 2012 at 11:42 AM JeanLuc

Thanks dude, worked like a charm

Feb 18 at 01:19 PM David Kamunyu
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x8540
x2184
x319

asked: Apr 09, 2010 at 04:23 AM

Seen: 26517 times

Last Updated: Feb 18 at 01:19 PM