- Home /
Changing material using an array
I'm trying to get a bit of code working that if a condition is met, it sets a material to a gameobject and if it is not met, it sets a different material. The code I have at the moment is:
var materials : Material[]; public static var Coloured : boolean;
function Update () { if (Coloured) renderer.material = Material[1]; else renderer.material = Material[0]; }
However, this returns the error 'Type System.Type does not support slicing'. Can anyone point me in the right direction? (I have set the materials in the inspector).
Answer by Mike 3 · Jun 29, 2010 at 08:40 PM
needs to be
renderer.material = materials[0];
like you named the variable up top
Whoops, I honestly don't know why I didn't notice that. Thanks for the reply.
Your answer
Follow this Question
Related Questions
Access specific GameObject in arrays 1 Answer
Vector 3 in array 1 Answer
Cache materials into List (or array) and restore from cached List? 0 Answers