Changing Skin/Texture with an Script?

Okaay guys, help me again, i have two problems with my TEAM SYSTEM, when i select a team, it spawns 2 players (should spawn only 1, me!), i can controll both, and the custom skins i made are being applied to my gun, not to my soldier.

Here’s my script (i don’t know if the problem is here):
using UnityEngine;
using System.Collections;

public class TeamMember : MonoBehaviour {

public Texture Wyvern_Green;
public Texture Wyvern_Red;
public Texture Wyvern_S;

int _teamID = 0;
public int teamID {
get { return _teamID; }
}

[RPC]
void SetTeamID(int id) {
_teamID = id;

SkinnedMeshRenderer mySkin = this.transform.GetComponentInChildren<SkinnedMeshRenderer>();

if(mySkin == null) {
Debug.LogError("Couldn't Find a SkinnedMeshRenderer!");
}

if (_teamID == 1)
mySkin.material.mainTexture = Wyvern_Red;
if (_teamID == 2)
mySkin.material.mainTexture = Wyvern_Green;
if (_teamID == 0)
mySkin.material.mainTexture = Wyvern_S;
}

}

Please don’t care about the parsings and simbols, i copied and pasted.

Hi, firstly you’ve not included any information about how the players are spawned so I can’t comment on that. However, the cause of the Gun changing texture and not the player is the line where you get the component in children. A quick way around that would be add mySkin as a serialised (or public) field and drag in the SkinnedMeshRenderer of the player into it in the inspector. That will ensure that you are changing the correct renderer’s texture. I hope that helps =)