x


Adding a Color Change Script to a Model

Having a previous question of mine answered on here I was able to obtain a script that changed the colors of the materials on a model I attached it to. It works like it should and I thank he who showed me. However there is something I don't understand. I have 2 tree models. Model A, I apply the script too, and the material for the Bark of the tree changes color, not the leaves. (I want the leaves to change.) Model B I change it to, and it changes the colors of the leaves, not the bark. So why is it working differently with different models? The only thing I can think of myself is that when I click on each tree and look at the Inspector, it shows the materials on the model. Model A has 2 materials, the first one it shows is that bark. Model B also has 2 models, the first one it shows is the leaves. Does it only apply to the first material shown? And if this is the problem, how can I get it to attach to the material I want? Any help is appreciated.

more ▼

asked Sep 14 '10 at 01:31 AM

Eric 8 gravatar image

Eric 8
2 3 3 3

Follow up: You can attach the script that changes the renderer.materials[i] to a tree, then make a prefab of that tree, and then place the prefab. This will mean that any new tree you place will change color in the same way. Additional question: How do you change the Emissive color or Spec color through scripting? I can only change the "main" color ....

Jan 16 '11 at 03:37 AM Charles Van Norman
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

You need to use the array renderer.materials[]. The code renderer.material is just a shortcut for renderer.materials[0], accessing the "first" material, but they aren't in a specific order.

more ▼

answered Sep 14 '10 at 02:28 AM

qJake gravatar image

qJake
11.6k 43 78 161

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

Oh wow that worked perfectly thanks! So another thing quick, I attached this script to the tree, now the leaves are changing color back and forth like they should. Is there any way to use this tree as a Brush so I can put down a lot of them and have them still keep the script? Or will I have to place them one by one?

more ▼

answered Sep 14 '10 at 03:19 AM

Eric 8 gravatar image

Eric 8
2 3 3 3

Once again, this should be commented to the answer that it refers to, not posted as a separate answer.

Sep 14 '10 at 03:35 AM Marowi

Oops, thanks, didn't notice.

Sep 14 '10 at 03:42 AM Eric 8
(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:

x5050
x3314
x807
x504
x228

asked: Sep 14 '10 at 01:31 AM

Seen: 2988 times

Last Updated: Sep 14 '10 at 01:31 AM