I am making a multi player game but i cant seem to figure out how to change the skin or material of the new players that join. I was reading around and i see that the following should change the material of a model. ANd just a fyi the data.skin works its a string called rain. and the material asset is in my game. https://playcanvas.com/editor/scene/1391191
Thank you so much Albertos. I finally got it working with the following.
Network.prototype.changeSkin=function(data,np){
var rain = this.materials[1];
var self = np;
var pb = this.materials[0];
var chosen = null;
if(data.skin=="rain"){
chosen = rain;
}else if (data.skin=="pb"){
chosen = pb;
}
var allMeshInstances = [];
var renders = self.findComponents('render');
for (i = 0; i < renders.length; ++i) {
var meshInstances = renders[i].meshInstances;
for (var j = 0; j < meshInstances.length; j++) {
allMeshInstances.push(meshInstances[j]);
}
}
for (i = 0; i < allMeshInstances.length; ++i) {
var mesh = allMeshInstances[i];
mesh.material = chosen.resource;
}
};
I didnt want to use one of thos script asset things but i have to apparently.