x


Change material color at runtime!!

I wonna change the color of the material at the runtime (particle system)!

var partColor : GameObject; 
function Update(){ 
if (Input.GetButton ("Jump")) {
partColor.renderer.material.color = Color.red; 
} 
}

Why doesnt it work? What am i doing wrong?

Celofa

more ▼

asked Jan 18 '11 at 09:14 AM

Celofa gravatar image

Celofa
82 15 15 24

(not edited, only added tag 'particles')

Jan 18 '11 at 09:43 AM efge
(comments are locked)
10|3000 characters needed characters left

5 answers: sort voted first

MaterialPropertyBlock might be what you're looking for: http://unity3d.com/support/documentation/ScriptReference/MaterialPropertyBlock.html

With it, meshes using the same material can be different colors.

more ▼

answered Jan 18 '11 at 09:36 PM

Dylan Fitterer gravatar image

Dylan Fitterer
33 1 1 8

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

answered Feb 19 '12 at 03:18 AM

DaveA gravatar image

DaveA
26.4k 151 171 256

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

The color of a particle can be modyfied by Particle.color.

more ▼

answered Jan 18 '11 at 09:41 AM

efge gravatar image

efge
5.1k 5 14 38

var partColor : Color; function Update () { partColor.particle.color = Color.red; }

like that?? sry iam really new to Unity?

Jan 18 '11 at 09:54 AM Celofa
(comments are locked)
10|3000 characters needed characters left

YourParticleTransform.GetComponent().material.SetColor("_TintColor", DesiredColour); Works if you are using Particle Materials

more ▼

answered Feb 19 '12 at 01:15 AM

m4a4 gravatar image

m4a4
1

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

Hello, well try this piece of code:

function Start () {

// Set glossy shader so that specular color is used renderer.material.shader = Shader.Find (" Glossy");

// Set red specular highlights

renderer.material.SetColor ("_SpecColor", Color.red); }

more ▼

answered Jan 18 '11 at 07:28 PM

Noah 1 gravatar image

Noah 1
1.1k 33 45 50

(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:

x807
x636
x504
x379
x374

asked: Jan 18 '11 at 09:14 AM

Seen: 9012 times

Last Updated: Feb 19 '12 at 03:18 AM