|
I have a character with 3 materials, and i want to change it by code, i already have a script to change a material, is there a way to specify which material from my object i want to change? Thanks
(comments are locked)
|
|
Yup i did, but there seemed to be a bigger problem, i share with you my solution... i had to firt take the materials my mesh already had and save it on a var... var Suits : Material[]; var Detail : Material[]; var currentSuitIndex : int = 0; var currentDetailIndex : int = 0; var currentSuit : Material; var currentDetail : Material; var currentSuitMat : Material[]; var ColorSuit : Color[] = [Color.red, Color.white, Color.blue, Color.green, Color.yellow, Color.black, Color.cyan, Color.magenta, Color.gray]; var currentSuitColorIndex : int = 0; var currentDetailColorIndex : int = 0; function Start () { } function ActivateSuit(index : int) { } function ChangeSuitColor(index : int) { } function ChangeDetailColor(index : int) { } function Update () { }
(comments are locked)
|
|
Yes you find the object within your character that has the material. If there is an array of materials, it will be indexed like any other array of things. Ok, i think i am doing something wrong, i used this and there is no error but nothing happend: `var Suits : Material[]; var currentSuitIndex : int = 0; var currentSuit : Material; function Start () { ActivateSuit(0); } function ActivateSuit(index : int) { if (index >= Suits.Length) { index = 0; } currentSuitIndex = index; currentSuit = Suits[currentSuitIndex]; renderer.sharedMaterials[1] = currentSuit; } function Update () { if (Input.GetKeyDown ("s")) { ActivateSuit(currentSuitIndex + 1); } }`
Jul 28 '11 at 06:08 PM
AlastorSparda
Best to edit your question to put code there cuz you can format it as code there.
Jul 28 '11 at 08:16 PM
DaveA
Assuming the 'suit' mesh is at index 1, this looks ok to me. Of course you have assigned the materials to the Suits array, right? Are you sure you want sharedMaterial? http://unity3d.com/support/documentation/ScriptReference/Renderer-sharedMaterial.html
Jul 28 '11 at 08:19 PM
DaveA
(comments are locked)
|
