Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by CJGames · Aug 03, 2014 at 03:43 PM · c#texturemultiplayerspawnteam

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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 =)

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image CJGames · Aug 04, 2014 at 04:29 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges