- Home /
This question was
closed Mar 09, 2014 at 01:13 AM by
Benproductions1 for the following reason:
The question is solved
Problem with changing material at runtime.
I'm pretty new at scripting so this is likely a novice question. I'm working on a project that loads a series of obj's at runtime one after another creating an animation from them. The animation is working so far but its not showing the material or texture when I play the game.
function waitFor()
{
if(boxCount == boxes.Length)
{
boxCount = 0;
}
var newBox : GameObject = Instantiate(boxes[boxCount], Vector3(0,0,0), Quaternion.identity);
var newTexture : Texture = boxTextures[boxCount];
newBox.AddComponent("MeshRenderer");
newBox.renderer.material = peopleMat;
newBox.renderer.material.mainTexture = newTexture;
print(newBox.renderer.material.mainTexture); //This is printing out the right texture but its not showing on the object.
boxCount++;
yield WaitForSeconds(0.042);
Destroy(newBox);
}
Comment
Figured it out. I was changing 'newBox' which was the prefab obj but I needed to access it's child object mesh.