x


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).

more ▼

asked Jun 29 '10 at 08:32 PM

Deikkan gravatar image

Deikkan
198 8 9 19

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

needs to be

renderer.material = materials[0];

like you named the variable up top

more ▼

answered Jun 29 '10 at 08:40 PM

Mike 3 gravatar image

Mike 3
30.5k 10 65 252

Whoops, I honestly don't know why I didn't notice that. Thanks for the reply.

Jun 29 '10 at 08:46 PM Deikkan
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1356
x274
x21

asked: Jun 29 '10 at 08:32 PM

Seen: 1916 times

Last Updated: Jun 29 '10 at 08:32 PM