Replace certain materials on a model

I’m sorry if this question has been answered already somewhere, but I’ve done some searching and I can’t find an answer that helps me.

My player model is a cube with a plane inside of it. Both shapes have different materials on them, and I want to change the material on only the plane of the model during run-time.

How can I do this?

2 Answers

2

Declare first

var plane: GameObject;
var planeTex: Texture;

Just drag and drop plane and textures as public parameters from unity scene.

In runtime code, give

plane.renderer.material.mainTexture = planeTex;

Hope this help you.

Thank you, that's just what I needed! :)

Happy to hear that it helped you. All the best for your game

Get the plane gameobject, then access gameObject.renderer.material Unity - Scripting API: Renderer.material

How do I get the plane's gameObject? If my plane's name is Plane001, would I use Plane001.gameObject? The plane is part of my .fbx model, can I still use the gameObject stuff? Sorry, I'm pretty confused.