What we’re attempting to do is to randomly select a texture from a folder of textures in the asset list, and apply that texture to a game object. No matter what we try the texture doesn’t seem to get applied, even if we forgo randomly generating the number and specify a specific texture it still doesn’t apply. I feel like if we can figure out how to apply a texture programmatically we can get the rest to work but even after consulting the unity script reference we’re still pretty stuck. here is the code we are working with so far.
using UnityEngine;
using System.Collections;
public class TestTexture : MonoBehaviour {
// Use this for initialization
void Start () {
GameObject.Find("Planet_3").renderer.material.SetTexture ("_MainTex",
(Texture)Resources.Load ("Assets/Standard Assets/Terrain Assets/Planet Textures/0"));
}
// Update is called once per frame
void Update () {
GameObject.Find("Planet_3").renderer.material.SetTexture ("_MainTex",
(Texture)Resources.Load ("Assets/Standard Assets/Terrain Assets/Planet Textures/0"));
}
}
its supposed to work by generating a random number (all of the textures are named for numbers) and then to use that number to select the desired texture and apply it to the game object.
can anyone tell us what we’re doing wrong, and recommend how to fix it?