C# Resources.Load() problem
Asked Answered
T

1

0

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

Tecla answered 6/6, 2023 at 1:48 Comment(1)

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

Jourdan
B
0

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.

Bronchopneumonia answered 6/6, 2023 at 2:5 Comment(5)

Thanks good answer.

Tecla

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").

Bondholder

thanks that did helped me

Diocese

Thanks dude, worked like a charm

Vickers

Seems like this nuance should go into the documentation for Resources.Load, no? It wasn't very clear to me. Thank you though!

Hesione

© 2022 - 2024 — McMap. All rights reserved.