- Home /
changing Texture on a material of a child object effecting all child game object of that prefab
Hi, i am using Unity 4.1.5 and i am currently working on a game. I have created some child objects of a prefab and when i try to change texture on one child object through script(or in editor) it effects to all child object of that prefab. how do i make change only to thatparticular object.
this.transform.renderer.sharedMaterial.mainTexture=color[carColorChanging.colorPointer];
this is what i have used in script. where color[carColorChanging.colorPointer] is a texture. Note:script is attached to only one child object
Answer by Tomer-Barkan · Oct 29, 2013 at 11:58 AM
sharedMaterial
is exactly that - it's the material shared by all gameobjects that use this specific material.
If you want to change only the specific object, use:
transform.renderer.material.mainTexture = color[carColorChanging.colorPointer];
this will create a duplicate of the material and assign it only to this object, leaving all the other objects that use this material unchanged.
Deleted my answer as its essentially the same as this one except 1 $$anonymous$$ute later.
Your answer
Follow this Question
Related Questions
Blender texture problem! 3 Answers
Textures don's show? 0 Answers
how to change image texture using C# 2 Answers
Textures making 1 Answer
How to size a texture for a object New to unity. Please Help 0 Answers