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 /
This question was closed Sep 10, 2017 at 09:00 PM by Zythus for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Zythus · Sep 07, 2017 at 01:06 PM · unity 5scripting problemnetworking

Rpc logic with bools, using tutorial scripts, can't find the flaw

I've got 2 scripts - PlayerDeath and MatchManager. MatchManager has a static List players and 3 static methods - AddPlayer, RemovePlayerAndCheckWinner and GetWinner. PlayerDeath script on the other hand has some RPCs in it, most notably when the player finishes or loses the level. There are 2 players, when one of them wins, the other one loses. Worked out well for me till now - I am trying to assign a bool that each player has finished the game, and after 2 bools are true, I can move on with other stuff. Thing is, with my current script I can't seem to achieve what I want.

When the hosting player finishes the game, and client tries to, he can't. The bool simply doesn't record. But when the client finishes the game first, the host's bool records and it is all good. Logic somewhere is flawed, but I can't pinpoint the problem, and I've been tinkering with it for quite some time. I know they look really simple, but I was working off of a tutorial and probably didn't comprehend these scripts' logic fully. Maybe someone here could point me in the right direction. Thank you.

Here is the code - Relevant PlayerDeath methods and RPCs. This first method SetFinishBools is called, when a player collides with the Finish line.

 public void SetFinishBools()    //Called when player collides with Finish line                
     {
         if (!isServer)
             return;
 
         RpcSetHostBool();
         if (MatchManager.RemovePlayerAndCheckWinner(this)) 
         {
             PlayerDeath player = MatchManager.GetWinner();
             player.RpcSetOpponentBool();
         }
         return;
     }
     [ClientRpc]
     void RpcSetHostBool()
     {
         if (isLocalPlayer)
             netManager.hostFinishedLevel = true; //A Syncvar bool from another script
     }
 
     [ClientRpc]
     void RpcSetOpponentBool()
     {
         if (isLocalPlayer)
             netManager.opponentFinishedLevel = true; //A Syncvar bool from another script
     }


And the MatchManager:

 public static List<PlayerDeath> players = new List<PlayerDeath>();
 
     public static void AddPlayer(PlayerDeath player)
     {
         players.Add(player);
     }
 
     public static bool RemovePlayerAndCheckWinner(PlayerDeath player)
     {
         players.Remove(player);
 
         if (players.Count == 1)
             return true;
 
         return false;
     }
 
     public static PlayerDeath GetWinner()
     {
         if (players.Count != 1)
             return null;
 
         return players[0];
     }

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
0
Best Answer

Answer by Akusan · Sep 07, 2017 at 02:27 PM

Add a script for host migration so that when server or host is disconnected then the a client automatically becomes the host

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 Zythus · Sep 07, 2017 at 02:54 PM 0
Share

So, something like this?: https://docs.unity3d.com/$$anonymous$$anual/UNetHost$$anonymous$$igration.html

avatar image Akusan Zythus · Sep 07, 2017 at 03:02 PM 0
Share

Try it and see if it works. $$anonymous$$aybe ins$$anonymous$$d of adding or removing player, just move them ins$$anonymous$$d by disabling their control, changing their transform position, re-enabling control. That way you don't mess up the onstart initializations

avatar image Zythus Akusan · Sep 08, 2017 at 01:26 PM 0
Share

I looked through Google and someone said that it can be easily distinguished between a server and a client with an if (isServer) and if (!isServer), but when I looked up Network Information in Inspector both players in my lobbyPanel and in game (host and client) are marked as server. How is that possible :/

Follow this Question

Answers Answers and Comments

199 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 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

Can I run unity with this system? 3 Answers

Is unity uses rendering from the cpu or gpu ? 2 Answers

How to make sure than one script affect the player of the specific client, and not the other 2 Answers

How do I use UNetWeaver.dll during runtime? 0 Answers

Getting a mix of warnings in multiplayer 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