- Home /
Material class use general question
In my JS I set a material variable:
var someMaterial: Material;
and later I want to test if the object that collides with the object that has this JS attached on it has "someMaterial" and do something:
if (col.gameObject.renderer.material == someMaterial){
...do something... }
This doesn't work, to be frank I haven't seen gameObject.renderer.material being used anywhere.
eg testing what color the collider has, using gameObject.renderer.material.color works. I want to use materials though.
How would I make this test?
Answer by Jessy · Jan 31, 2011 at 10:20 PM
http://unity3d.com/support/documentation/ScriptReference/Renderer-sharedMaterial.html
Renderer.material is an instance, not a reference to the original.
if (col.gameObject.renderer.sharedMaterial == someMaterial)
Should've read the scripting overview more carefully. Thank you Jessy!
Your answer
Follow this Question
Related Questions
Changing two different objects renderer colour 1 Answer
Changing material of objects by the tag in different scenes 0 Answers
Gameobject not the right color 0 Answers
appear/disappear gameobject 3 Answers