Right, after messing about with a function that was not working properly I think I've hunted it down to this specific (stripped down) part of the function.
I have three textures in an array and a prefab gameobject. In the loop I instantiate the gameobject, create a material, assign the corresponding texture, assign the material and again and again. Say the materials say 1, 2 and 3. I'd expect to get:
1 2 3
instead I get
X 2 3
where x is no material assigned. I'm extremely confused and have been driven crazy by this all day. What am I doing wrong here? yells out in agony
var tex1 : Texture2D;
var tex2 : Texture2D;
var tex3 : Texture2D;
var textures = new Array ();
var card : GameObject;
function Awake () {
textures.Add(tex1,tex2,tex3);
}
function Start () {
for(var i=0; i<3; i++){
Instantiate(card, Vector3(2*i,0,0), Quaternion.identity);
var mat : Material = new Material(Shader.Find("Diffuse"));
mat.mainTexture = textures*;*
*card.renderer.material = mat;*
*}*
*}*
*```*
_<p>Note: if I replace textures *with i+1 I get X 3 4.. so that's not it. =\</p>*_