Resources.Load Problem

In a Quiz game, depending on the answer ( if Input.GetKeyDown…), I want to apply a texture to an object and to play a sound.
Problem is this minute function does not display the texture AND play the sound (the object is displayed completely white and the sound is played). Why?

void the_event (int the_input)	{
    obj = GameObject.Find ("Rectangle");
    obj.renderer.material.mainTexture = Resources.Load (matrix [the_input, 2]) as Texture;
    sound = matrix [the_input, y];
    audio.clip = Resources.Load (sound) as AudioClip;
    audio.Play ();
    }

Based on what lines I disable, the function correctly applies the texture OR plays the sound.
The white “texture” might signify a null return from that Ressources.Load.

I don’t understand what the problem is.
Should I break the response into separate frames? Frame 1 - texture, frame 2 - sound?
Should I do a LoadAll in Start() ? Not sure how I would address what I need then…

Heeeelp :slight_smile:

My problem had been caused by having the same name for both the sound and the photo files.
As soon as I differentiated them (like “comet” for photo and comet_s for sound), the code worked.

I guess I had assumed that by specifying “as Texture” or “as AudioClip” Unity would choose the .wav for the first and the .jpg for the second.

As I cannot delete my own thread, I have no alternative but to answer my own question…:slight_smile:

PROBLEM SOLVED (if it was a problem)

P.S. Usefull at this stage was the use of coroutines (IEnumerator and such) to get a timed series of events over several seconds from a single command.