Resources.LoadAll

static function LoadAll (path : String, systemTypeInstance : Type) : Object[]

Description

Loads all assets in a folder or file at path in a Resources folder.

If path refers to a folder, all assets in the folder will be returned. If path refers to a file, only that asset will be returned. Only objects of type will be returned. The path is relative to any Resources folder inside the Assets folder of your project.

JavaScript
// Loads all assets in the "Resources/Textures" folder
// Then picks a random one from the list.
// Note: Random.Range in this case returns [low,high)
// range, i.e. the high value is not inclusive.

function Start (){
var go = new GameObject.CreatePrimitive(PrimitiveType.Cube);
var textures : Object[] = Resources.LoadAll("Textures", Texture2D);
var texture : Texture2D = textures[Random.Range(0, textures.Length)];
go.renderer.material.mainTexture = texture;
}

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
void Start() {
GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cube);
Object[] textures = Resources.LoadAll("Textures", typeof(Texture2D));
Texture2D texture = textures[Random.Range(0, textures.Length)];
go.renderer.material.mainTexture = texture;
}
}

import UnityEngine
import System.Collections

class example(MonoBehaviour):

def Start():
go as GameObject = GameObject.CreatePrimitive(PrimitiveType.Cube)
textures as (Object) = Resources.LoadAll('Textures', Texture2D)
texture as Texture2D = textures[Random.Range(0, textures.Length)]
go.renderer.material.mainTexture = texture

static function LoadAll (path : String) : Object[]

Description

Loads all assets in a folder or file at path in a Resources folder.

If path refers to a folder, all assets in the folder will be returned. If path refers to a file, only that asset will be returned. The path is relative to any Resources folder inside the Assets folder of your project.

JavaScript
// Loads all assets in the "Resources/Textures" folder
// Then picks a random one from the list.
// Note: Random.Range in this case returns [low,high)
// range, i.e. the high value is not inclusive.

function Start (){
var go = new GameObject.CreatePrimitive(PrimitiveType.Cube);
var textures : Object[] = Resources.LoadAll("Textures");
var texture : Texture2D = textures[Random.Range(0, textures.Length)];
go.renderer.material.mainTexture = texture;
}

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
void Start() {
GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cube);
Object[] textures = Resources.LoadAll("Textures");
Texture2D texture = textures[Random.Range(0, textures.Length)];
go.renderer.material.mainTexture = texture;
}
}

import UnityEngine
import System.Collections

class example(MonoBehaviour):

def Start():
go as GameObject = GameObject.CreatePrimitive(PrimitiveType.Cube)
textures as (Object) = Resources.LoadAll('Textures')
texture as Texture2D = textures[Random.Range(0, textures.Length)]
go.renderer.material.mainTexture = texture