Searching for a specific material named COIN and assigning a new texture to it can be achieved by looping through the materials in an object. The goal is to find a match based on the material name, regardless of its index within the material array.
object.traverse( function( node ) {
if (node.isMesh) {
if ( node.material[0].name == 'COIN' ) {
node.material = textura
}
}
})
// This method works flawlessly
An attempt to access the material without knowing its index might lead to an error:
if ( node.material[].name == 'COIN' )
// Error
To avoid such errors, it's crucial to iterate through the object's materials until the desired material with the specified name is found. It's worth mentioning that the object format in this scenario is FBX.
Thank you!