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 /
This question was closed Jul 03, 2015 at 04:33 PM by DiebeImDunkeln for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by DiebeImDunkeln · Jul 01, 2015 at 07:28 PM · networkingmultiplayerclienthost

Multiplayer problem

Hi,

I make a multiplayer tank fighting game with the new Unity5 network features. In general my multiplayer setup is working now. I have the problem, that I see my host shoots and detonations in both, client and host, but not the client shoots and detonations. This are only visible on the client side.

alt text

I know I have to sync it, but the documentation not really complete yet and I don't know when to use [ClientBehavior] [Command] and [Syncvar]

I would be happy about a little help. Thanks. Frank

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

  • Sort: 
avatar image
1
Best Answer

Answer by n1gth · Jul 02, 2015 at 08:41 PM

You need to do almost everything on the server. Although a client or human player might decide to shoot, it's the decision that happens on the client, not the actual firing. The client commands the server to do it. You can use the Command for this, eg:

     [Client] // runs only on client
     public void Shoot(Vector3 target)
     {
         CmdShoot(target, identity);
     }
 
     [Command] // runs only on server
     private void CmdShoot(Vector3 target)
     {
         var obj = (GameObject)Instantiate(TankShellPrefab, MyTranform, someRotation);
         NetworkServer.Spawn(obj);
         // etc
         RpcTankEventHappened("shot");
     }

     [ClientRpc] // runs only on client
     public void RpcTankEventHappened(string something)
     {
         if (something.Equals("shot")) {
           // decrease on-screen ammo count
         }
     }

Note that for this to work you need be in a NetworkBehavior, and have the NetworkIdentity and NetworkTransform on the Prefab, but I think you have these already.

See the docs for the ClientRPC call for more details of server -> client high-level messaging, for informing the client that something's happened (like damage).

Comment
Add comment · Show 3 · 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 DiebeImDunkeln · Jul 03, 2015 at 06:38 AM 0
Share

thanks for your answer. Looks good, I will check it this evening. But it helps really to understand the commands.

avatar image DiebeImDunkeln · Jul 03, 2015 at 04:33 PM 0
Share

I tested it and it works like charm! :-)

avatar image n1gth · Jul 03, 2015 at 04:58 PM 0
Share

Cool, that's great.

Follow this Question

Answers Answers and Comments

22 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

Related Questions

Unity networking tutorial? 6 Answers

Networking sending info only one direction 0 Answers

Requesting data from server 1 Answer

Using AssignClientAuthority 0 Answers

Can a person be both a client and a server? (and more) 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