- Home /
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.
Answer by Chris_Dlala · Aug 03, 2014 at 08:49 PM
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 =)
First of all, i'm not american, so could you explaim better or give me the full code on the texture problem?
Second, i'm sorry i forgot to put the Spawn code, but first i have to tell that i'm using Photon Network System from Assets Store, second i have some variables and stuff, and third this is not the entire code, but i think this is all that you need to know to solve my problem, so here it is:
void Connect() {
PhotonNetwork.ConnectUsingSettings( "Battle Strike Alpha v004" );
void OnJoinedLobby() {
Debug.Log ("OnJoinedLobby");
PhotonNetwork.JoinRandomRoom();
}
void OnPhotonRandomJoinFailed() {
Debug.Log ("OnPhotonRandomJoinFailed");
PhotonNetwork.CreateRoom( null );
}
void OnJoinedRoom() {
Debug.Log ("OnJoinedRoom");
connecting = false;
//Spawn$$anonymous$$yPlayer();
}
void Spawn$$anonymous$$yPlayer(int $$anonymous$$mID) {
this.$$anonymous$$mID = $$anonymous$$mID;
hasPickedTeam = true;
AddChat$$anonymous$$essage("Spawning player: " + PhotonNetwork.player.name);
Screen.showCursor = false;
if(spawnSpots == null) {
Debug.LogError ("WTF?!?!?");
return;
}
SpawnSpot mySpawnSpot = spawnSpots[ Random.Range (0, spawnSpots.Length) ];
GameObject myPlayerGO = (GameObject)PhotonNetwork.Instantiate("PlayerController", mySpawnSpot.transform.position, mySpawnSpot.transform.rotation, 0);
standbyCamera.SetActive(false);
//(($$anonymous$$onoBehaviour)myPlayerGO.GetComponent("FPSInputController")).enabled = true;
(($$anonymous$$onoBehaviour)myPlayerGO.GetComponent("$$anonymous$$ouseLook")).enabled = true;
(($$anonymous$$onoBehaviour)myPlayerGO.GetComponent("Player$$anonymous$$ovement")).enabled = true;
(($$anonymous$$onoBehaviour)myPlayerGO.GetComponent("PlayerShooting")).enabled = true;
myPlayerGO.GetComponent<PhotonView> ().RPC ("SetTeamID", PhotonTargets.AllBuffered, $$anonymous$$mID);
myPlayerGO.transform.FindChild("$$anonymous$$ain Camera").gameObject.SetActive(true);
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Players not moving properly - Network Multiplayer 1 Answer
Sequencing Spawning for Multiplayer 1 Answer
NPC does not follow player movement 0 Answers