Apply a material to children

Hi everyone,

I am working on a game where the player is going to create a lot of objects ( but the nulber of different objects is not so huge).

I am trying to optimize the grpahics so I wanted to apply a materail to all the children, in order to reduce the number of draw calls.

Does anyone knw how to do that dynamically, using one renderer for the hundred of objects using the same material?

Thnaks in advance
Cheers,
Gamejie

4 Answers

4

http://unity3d.com/support/documentation/ScriptReference/Renderer-sharedMaterial.html

Do you have a piece of code using it?

Thanks a lot anyway

var goRenderers : Renderer;
var mat : Material;

for (var r : Renderer in goRenderers) {
    r.sharedMaterial = mat;
}

Thanks a lot guys

Did you end up getting this working? If so, you should help other people who may have the same problem by accepting the answer which helped you. Also, please don't put comments as answers. :)

If you want to subtract, you need to use health-= 1 or whatever u want to subtract.

ahh thank you, the guy in the video had it as - 10 and i saw in the comments something about =10 but thank you very much!!

If you could, either accept my answer or the guy's answer below which is more detailed, so people will know this has been resolved.