- Home /
Renderer.material not cloning?
I have a prefab which I would like to fade out the alpha on without fading out the alpha on all objects with that material. In the documentation it says the material should be cloned once changed but it's doesn't seem to do that in my project. I'm developing for Android, should that make any difference?
if (a > 0.0)
{
a = a - 1.0/30.0;
object.renderer.material.color.a = a;
}
else
{
Destroy(gameObject);
}
Answer by mrdoktor1974 · Oct 05, 2011 at 08:05 AM
I found the problem. Both of my objects acted as if clicked because I was using an examplescript that wasn't specific to one object. ()
Have you got any good example of how to track if an item is "touched". I tried using RaycastHit but the variables "collider" and "rigidbody" is empty in the debugger.,My script is definitely entering the if statement, because it fades out all instances of the prefab. I'm not calling renderer.sharedMaterial, I'm calling renderer.material.
After clicking one of my objects both get (Instance) after the material name.
Now I'm starting to think that both objects pick up the click (touch).
Answer by mrdoktor1974 · Oct 05, 2011 at 08:05 AM
My bad. I was using an example that wasn't intended for this kind of function. So whenever a Raycast hit an object all my prefabs acted as if clicked.
Have you got any examples of clicking/touching objects? I've tried using RaycastHit but the variable collider return null.
Answer by loopyllama · Oct 05, 2011 at 06:15 AM
renderer.material will instance a material and break any possible batching while renderer.sharedMaterial will not.
for your specific case, either it is a material instance and you haven't realized it (check the material on the object during gameplay for the Instance text next to the material name in the Inspector) or your script is not getting inside the "if" statement and thus not creating a material instance.
Your answer
Follow this Question
Related Questions
Changing two different objects renderer colour 1 Answer
Fade out a material that has a texture 1 Answer
Material doesn't have a color property '_Color' 4 Answers
How to Make a Character Flicker? 1 Answer
Can't animate Material.Color properties 3 Answers