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

avatar image

Exotic Utopia
38 1 2 8

@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

I'm in a similar situation, I'd like to change the Resources.Load("A string") as texture; with the replace function, allowing the texture to changed with logic at runtime.

YES: you could just list all your textures in an array and select that way, but rather make it more efficient. -esp as I have 100 odd textures to update on runtime.

so far the closest i've got :

Void Update { {

Texture Startingframe = Resources.Load("frame_000") as Texture;

frameselectED = frameselect.Replace("000", "092");

renderer.material.mainTexture = Startingframe; } }

the frameselectED can then obv be changed with some arithmetic.

Dec 28, 2014 at 11:40 PM sirshelley
(comments are locked)
10|3000 characters needed characters left

0 answers: 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

avatar image

TrolleFar
146 2 6 5

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 sky_02 to Resources/Textures and use Resources.Load("Textures/sky_02").

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, 2014 at 01:19 PM David Kamunyu
(comments are locked)
10|3000 characters needed characters left
Be the first one to answer this question
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:

x2258
x390

asked: Apr 09, 2010 at 04:23 AM

Seen: 36577 times

Last Updated: Dec 28, 2014 at 11:40 PM