Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Fantastic Worlds Studio · Feb 16, 2016 at 12:56 PM · multiplayer networking

Multiplayer Problem: How to Change child object color on all instances of player?

I'm making a multiplayer PvP game where the players choose one of four factions, each with a color (red, blue, green, and yellow), and I have armor and weapons that should have their faction's colors applied to the highlight material of their respective items.

For instance, when Player A chooses the Red faction, their helmet, shield and sword highlight materials should change to red, not only on the local client, but on all clients' Player A's instances. I am new and confused by the Unity multiplayer code right now, and am trying hard not to give up. I have searched the sites for days for answers but I can't get anything to work properly.

Right now, to test, I have two cubes added to the test scene with code in the collider trigger to call the rpc method on the client's player object to change their color, but it only changes on the client's view, not updated and synced on all clients.

Cube code: using UnityEngine; using UnityEngine.Networking;

 public class FactionChoice : NetworkBehaviour 
 {
     public Faction FactionChange;
     void OnTriggerEnter(Collider other)
     {
         if(other.tag == "Player")
         {
             other.gameObject.GetComponent<PlayerNetworkControl>().CmdChangeFaction(other.gameObject, FactionChange);
         }
     }
 }

PlayerNetworkControl code: using UnityEngine; using UnityEngine.Networking;

 public class PlayerNetworkControl : NetworkBehaviour
 {
     //make public variables to reference scripts to turn on
     public GameObject PlayerCamera;
     public UnityStandardAssets.Characters.ThirdPerson.ThirdPersonUserControl Control;
     public UnityStandardAssets.Characters.ThirdPerson.ThirdPersonCharacter Character;
     private Material[] HelmetMaterials;
 
     //Worn and equipped items
     public GameObject Helmet;
 
     [SyncVar]
     private GameObject MyID;
     [SyncVar]
     public Faction MyFaction;
     [SyncVar]
     private Color FactionColor;
 
     private NetworkIdentity NetworkID;
 
     public override void OnStartLocalPlayer()
     {
         //turn on scripts here
         PlayerCamera.GetComponent<Camera>().enabled = true;
         Control.enabled = true;
         Character.enabled = true;
         GetComponent<PlayerActions>().enabled = true;
         PlayerCamera.GetComponent<AudioListener>().enabled = true;
 
         //if fighter, right now, everyone is a fighter!
         Helmet.SetActive(true);
         //attempt to change the highlight material color
         HelmetMaterials = Helmet.gameObject.GetComponent<Renderer>().materials;
         //set name here for debugging
         gameObject.name = "Local Player";
 
         base.OnStartLocalPlayer();
     }
 
     [Command]
     public void CmdChangeFaction(GameObject PlayerAffected, Faction ChangedTo)
     {
         NetworkID = PlayerAffected.GetComponent<NetworkIdentity>();
         NetworkID.AssignClientAuthority(connectionToClient);
         RpcChangeMyFaction(PlayerAffected, ChangedTo);
         NetworkID.RemoveClientAuthority(connectionToClient);
     }
 
     [ClientRpc]
     public void RpcChangeMyFaction(GameObject Player, Faction NewFaction)
     {
         MyFaction = NewFaction;
         
         switch(NewFaction)
         {
             case Faction.Blue: FactionColor = Color.blue; break;
             case Faction.Green: FactionColor = Color.green; break;
             case Faction.Red: FactionColor = Color.red; break;
             case Faction.Yellow: FactionColor = Color.yellow; break;
         }
         Player.transform.FindChild("helmet").gameObject.GetComponent<Renderer>().material.color = FactionColor;
     }
 }
 
 public enum Faction
 {
     Red,
     Yellow,
     Green,
     Blue
 }

Any help would be greatly appreciated.

Comment
Add comment · Show 3
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 Fantastic Worlds Studio · Feb 17, 2016 at 06:05 PM 0
Share

Never$$anonymous$$d, I give up. The networking in Unity is too complicated for me to understand and there aren't enough resources or tutorials for this to be a feasible project for one person.

avatar image meat5000 ♦ Fantastic Worlds Studio · Feb 17, 2016 at 06:06 PM 0
Share

Nah dont give up, you look so close.

avatar image Fantastic Worlds Studio · Feb 21, 2016 at 08:12 PM 0
Share

I've been playing in j$$anonymous$$onkeyEngine, and I GET the networking there. Perhaps I should delve deeper into the API or write my own. Honestly, I had to dump Windows and the Unity Linux Editor works only half the time I install it.

0 Replies

· Add your reply
  • Sort: 

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Need Server to Find NetworkIdentity Components AFTER Initialization 0 Answers

What is the CCU AND Where can i find about unit's relay server? 0 Answers

Multiplayer plugin 1 Answer

Unity Matchmaking not working on different routers. 1 Answer

Which Game Objects need Network Identities and which game objects don't in order to transfer data between the server and the client? 1 Answer


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