How to apply textures randomly to objects?,How do you apply textures to objects(Cubes)?

using UnityEngine;
using System.Collections;

public class Zombie : MonoBehaviour {
private GameObject player;
public float speed =5f;
public GameObject HUD;

// Use this for initialization
void Start () {
    player = GameObject.Find("mainPlayer");

    Texture2D[] textures = Resources.LoadAll<Texture2D>("Textures");
    Texture2D texture = textures[Random.Range(0, textures.Length)];
    HUD.GetComponent<Renderer>().material.mainTexture = texture;

}

// Update is called once per frame
void Update () {
transform.position = Vector3.MoveTowards(transform.position, player.transform.position , speed * Time.deltaTime);

}

}

I have this code for a zombie game and I need to get each zombie that spawns to basically be a different pattern. I have a folder named “textures” and set this code up for it, but it won’t work. The zombies(which are cubes) are still just white. Any suggestions?,

First, check that you’re actually getting textures from Resources.LoadAll. Second, try MeshRenderer instead of just Renderer. Third, try sharedMaterial instead of material. Finally, is this Textures folder inside of the Resources folder? It has to be. Otherwise, assign the textures in the inspector via a public Texture2D, I’d suggest doing this on a single Game Object (Texture Holder) that you can reference that script. Doing Resources.LoadAll on multiple game objects at start is just going to kill your loading time.