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

Resources.Load

Discussion in 'Scripting' started by Daniel-Greenhorn, Nov 27, 2014.

  1. Daniel-Greenhorn

    Daniel-Greenhorn

    Joined:
    Nov 6, 2014
    Posts:
    3
    Hey, guys and girls

    Let's talk a bit about Resources.Load and why apparently it would not work to load a texture onto an object and to load a sound and play it. Simple loads work fine.

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

    By matrix [index, x] I meant the string at row "index" and column "x" in a 2D array.
    If I disable either load line (//) the other works correctly.
    Both loads don't work together (either object gets a white texture (null, I believe?!) and the sound plays or, if there is no sound by that name, the texture is applied correctly).
    Even splitting this function in the 2 segments and calling them does not work.

    What is the problem? Or, better yet, how would you do it, in this case?
     
    Last edited: Nov 28, 2014