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 Handy4 · Jun 10, 2016 at 12:09 PM · networkingmultiplayerspawning

Networking Question: Spawning selectively / on only one client.

Hello everyone,

I am currently learning networking in Unity for a university project and I slowly feel like I am getting a good grasp of the basics.

I am implementing a turn based digital Trading Card Game. My idea was to handle the decks server side until a player actually needs to see the cards. Now instead of spawning the cards for all players and hiding them for the opponents when they are drawn I want to implement it like this (for anti-cheating and whatever reasons, imo this makes more sense):

 [Server]
 void OnCardDraw() {
     card.MoveToHand();
     NetworkServer.Spawn(card) //FOR OWNER OF CARD ONLY
 }

 [Server]
 void OnCardPlay() {
     card.MoveToField();
     NetworkServer.Spawn(card) //FOR OTHER PLAYER
 }

So now my question is: Is this possible? If yes, how? If not, how would you handle this so the other client gets the smallest possible amount of information about the card. For now I don't care if the opponent can see my hand with the backs of my cards.

I'm really hitting a wall here

Thanks a lot in advance! I really appreciate it!

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
1

Answer by EpiFouloux · Jun 15, 2016 at 08:23 AM

here are the basics :

 [Command] // called from a client, executed on Server
 
 [ClientRpc] // Called from server, executed on clients
 
 bool isLocalPlayer // is it the local player ?

so when playing a card, here what it should look like :

 public class player : NetworkBahaviour
 {
  void Update()
  {
   if (!isLocalPlayer)
     return ;
    // you are on the local player
    // handle input
    play(); // place conditions of course
  }
 
  void play()
  {
   Cmd_play_a_card(card_id);
  }
 
  [Command]
  private void Cmd_play_a_card(int id)
  {
    // this is executed on the server version of this player instance
   Rpc_move_card(id)
  }
  
  [ClientRpc]
  private void Rpc_move_card(int id)
  {
    if (isLocalPlayer)
       moveToHand(id);
    else
        moveToField(id);
  }
 }

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Unity networking tutorial? 6 Answers

Players Not Showing 0 Answers

Is it possible to create network objects from editor 0 Answers

HLAPI: How to spawn players from preGameScene 1 Answer

Spawning bullets on host and client Networking 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