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 mbahrami642 · Jul 28, 2018 at 04:04 PM · networkingnetworkcoroutinescommandactivation

Characters gun dosent activate on network?

hi. i have a networked game that characters should get a gun on start (when they join the game). i have wrote this script and attached it to the characters game object and it seem to work fine but there is one problem : new players that join the game don't see others guns. and i have no idea why is this happening? here is my activation script:

 void Start()
     {
         ActivateSimpleGun();
     }
 
 public void ActivateSimpleGun()
     {
         StartCoroutine(ActiveSGRoutine());
     } 
 IEnumerator ActiveSGRoutine()
     {
         //this waits for the diactivation to complete 
         //(in case a new gun was equipped and we want to change it
         NetworkWeaponDiactivate();
         
         yield return new WaitUntil(() => AllGunsDiactive == true);
         
         if (isServer) RpcActiveSG();
         else CmdActiveSG();
         
     }
 [Command]
     void CmdActiveSG()
     {
         SimpleGun.SetActive(true);
         WhichGunisOn = 1;
         AllGunsDiactive = false;  
         RpcActiveSG();
     }
     [ClientRpc]
     void RpcActiveSG()
     {
         SimpleGun.SetActive(true);
         WhichGunisOn = 1;
         AllGunsDiactive = false;      
     }
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
Best Answer

Answer by mbahrami642 · Jul 29, 2018 at 12:32 PM

For anybody who runs into this problem: i found a solution. on every players start i check and find other players in the scene and then check in their weaponpicking script and see what gun is active on them and place the gun for that character (activate it from its childrens ). im sure this is not the best way but it seems to work for now. this the loop to do it:

     private GameObject[] AllPlayers;
 
 AllPlayers = GameObject.FindGameObjectsWithTag("Player");
         for (int i=0; i < AllPlayers.Length; i++)
         {
             var CheckingPlayer = AllPlayers[i].GetComponent<WeaponPickingSystem>();
             if (!CheckingPlayer.isLocalPlayer)
             {
                 if (CheckingPlayer.WhichGunisOn == GUN_TYPE.simpleGun)
                 {
                     CheckingPlayer.SimpleGun.SetActive(true);
                 }
                 if (CheckingPlayer.WhichGunisOn == GUN_TYPE.secondGun)
                 {
                     CheckingPlayer.SecondGun.SetActive(true);
                 }
             }
             
         }
Comment
Add comment · 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

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

153 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Trying to send command for object without authority. - change color of object from client 0 Answers

Unity Networking client interaction with scene not displayed on other client. Commands and RPCs 0 Answers

"Trying to send command for object without authority" warning but the object is the localPlayer 1 Answer

Non player objects movements are not syncronized on server 0 Answers

Cmd on a runtime created object 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