- Home /
Answer about mainTexture
When i have two meshes renderers as child of a empty object, how to define the main object with the mainTexture, when i call renderer.material.mainTexture
( the script is attached in the parent object).
I'd like the object "Top" has the mainTexture. The mesh is exported from 3ds Max (fbx). Can anyone help me?
Answer by Kourosh · May 15, 2011 at 01:19 PM
If it's attached to the parent you can address a specific gameobject using either way:
1.If children are already there before running the game you can simply define a gameobject variable and assign the child to it.
var top:GameObject;
top.renderer.material.mainTexture = ....;
2.Use this way if your children are dynamically being added or removed and also if you know their names.
var top:GameObject = transform.Find("top").gameObject;
top.renderer.material.mainTexture = ....;
I need to do this dynamically, and this solution works perfectly, thanks!
Your answer
Follow this Question
Related Questions
Changing two different objects renderer colour 1 Answer
Why hitRender.sharedMaterial.mainTexture is Null? 0 Answers
Parent component affect child objects 0 Answers
Make a simple tree 1 Answer
change child texture problem 2 Answers