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 /
  • Help Room /
avatar image
1
Question by wasicool7 · Nov 05, 2016 at 06:55 PM · errormultiplayer-networking

Unity2D: Creating a Cross-Platform Multi-Player Game in Unity Error!

Hi, i'm following this tutorial on raywenderlich to do with multiplayer, since Unity updated, they have added a new method for the participant lefting the event. So I am getting this error on Unity:

Assets/Script/Multiplayer/GPG Multiplayer/MultiplayerController.cs(8,14): error CS0738: MultiplayerController' does not implement interface member > GooglePlayGames.BasicApi.Multiplayer.RealTimeMultiplayerListener.OnParticipantLeft(GooglePlayGames.BasicApi.Multiplayer.Participant)' and the best implementing candidate MultiplayerController.OnRoomSetupProgress(float)' return type void' does not match interface member return type `void'

Whilst following the tutorial, I saw that someone in the comment section had the same error as me and someone replied back, however I wasn't sure how I should implement it as he didn't really explain it in great and clear detail!I also do not know how to create my own OnParticipantLeft(Participant leavingPlayer) method, which is why I was following the tutorial!

Hmm... looks like since this tutorial was written, they've added a new method or two to that interface. Here's the new method they're expecting to see

/// /// Raises the participant left event. /// This is called during room setup if a player declines an invitation /// or leaves. The status of the participant can be inspected to determine /// the reason. If all players have left, the room is closed automatically. /// /// name="participant">Participant that left void > OnParticipantLeft(Participant participant); If you just want to get > your project going again, you can add your own > OnParticipantLeft(Participant leavingPlayer) method to your > MultiplayerController object and have it print out a debug message or > two. > > In an actual game, you could probably use this to make sure, say, your > lobby display doesn't get messed up if a player joins, then leaves > while you're waiting for a third or fourth player to join.

So anyway does anyone know how to fix this error? Below is my code:

    using UnityEngine;
    using UnityEngine.SceneManagement;
    using System.Collections;
    using GooglePlayGames;
    using GooglePlayGames.BasicApi.Multiplayer;
    using System.Collections.Generic;

  public class MultiplayerController : RealTimeMultiplayerListener 
   {
 public MPLobbyListener lobbyListener;
 private static MultiplayerController _instance = null;
 private uint minimumOpponents = 1;
 private uint maximumOpponents = 1;
 private uint gameVariation = 0;
 private byte _protocolVersion = 1;
 // Byte + Byte + 2 floats for position + 2 floats for velcocity + 1 float for rotZ
 private int _updateMessageLength = 22;
 private List<byte> _updateMessage;
 public MPUpdateListener updateListener;



 public string GetMyParticipantId() {
     return PlayGamesPlatform.Instance.RealTime.GetSelf().ParticipantId;
 }

 public List<Participant> GetAllPlayers() {
     return PlayGamesPlatform.Instance.RealTime.GetConnectedParticipants ();
 }

 private void StartMatchMaking() {
     PlayGamesPlatform.Instance.RealTime.CreateQuickGame (minimumOpponents, maximumOpponents, gameVariation, this);
 }

 private MultiplayerController() {
     _updateMessage = new List<byte>(_updateMessageLength);
 PlayGamesPlatform.DebugLogEnabled = true;
     PlayGamesPlatform.Activate ();
 }

 private void ShowMPStatus(string message) {
     Debug.Log(message);
     if (lobbyListener != null) {
         lobbyListener.SetLobbyStatusMessage(message);
     }
 }

 public void SendMyUpdate(float posX, float posY, Vector2 velocity, float rotZ) {
     _updateMessage.Clear ();
     _updateMessage.Add (_protocolVersion);
     _updateMessage.Add ((byte)'U');
     _updateMessage.AddRange (System.BitConverter.GetBytes (posX));  
     _updateMessage.AddRange (System.BitConverter.GetBytes (posY));  
     _updateMessage.AddRange (System.BitConverter.GetBytes (velocity.x));
     _updateMessage.AddRange (System.BitConverter.GetBytes (velocity.y));
     _updateMessage.AddRange (System.BitConverter.GetBytes (rotZ));
     byte[] messageToSend = _updateMessage.ToArray(); 
     Debug.Log ("Sending my update message  " + messageToSend + " to all players in the room");
     PlayGamesPlatform.Instance.RealTime.SendMessageToAll (false, messageToSend);
 }

 public void SignInAndStartMPGame() {
     if (! PlayGamesPlatform.Instance.localUser.authenticated) {
         PlayGamesPlatform.Instance.localUser.Authenticate((bool success) => {
             if (success) {
                 Debug.Log ("We're signed in! Welcome " + PlayGamesPlatform.Instance.localUser.userName);
                 StartMatchMaking();
             } else {
                 Debug.Log ("Oh... we're not signed in.");
             }
         });
     } else {
         Debug.Log ("You're already signed in.");
         StartMatchMaking();
     }
 }

 public void SignOut() {
     PlayGamesPlatform.Instance.SignOut ();
 }

 public bool IsAuthenticated() {
     return PlayGamesPlatform.Instance.localUser.authenticated;
 }

 public void TrySilentSignIn() {
     if (! PlayGamesPlatform.Instance.localUser.authenticated) {
         PlayGamesPlatform.Instance.Authenticate ((bool success) => {
             if (success) {
                 Debug.Log ("Silently signed in! Welcome " + PlayGamesPlatform.Instance.localUser.userName);
             } else {
                 Debug.Log ("Oh... we're not signed in.");
             }
         }, true);
     } else {
         Debug.Log("We're already signed in");
     }
 }

 public static MultiplayerController Instance {
     get {
         if (_instance == null) {
             _instance = new MultiplayerController();
         }
         return _instance;
     }
 }

 public void OnRoomSetupProgress (float percent)
 {
     ShowMPStatus ("We are " + percent + "% done with setup");
 }

 public void OnRoomConnected (bool success)
 {
     if (success) {
         ShowMPStatus ("We are connected to the room! I would probably start our game now.");
         lobbyListener.HideLobby();
         lobbyListener = null;
         SceneManager.LoadScene("MainGame");
     } else {
         ShowMPStatus ("Uh-oh. Encountered some error connecting to the room.");
     }
 }

 public void OnLeftRoom ()
 {
     ShowMPStatus ("We have left the room. We should probably perform some clean-up tasks.");
 }

 public void OnPeersConnected (string[] participantIds)
 {
     foreach (string participantID in participantIds) {
         ShowMPStatus ("Player " + participantID + " has joined.");
     }
 }

 public void OnPeersDisconnected (string[] participantIds)
 {
     foreach (string participantID in participantIds) {
         ShowMPStatus ("Player " + participantID + " has left.");
     }
 }

 public void OnRealTimeMessageReceived (bool isReliable, string senderId, byte[] data)
 {
     // We'll be doing more with this later...
     byte messageVersion = (byte)data[0];
     // Let's figure out what type of message this is.
     char messageType = (char)data[1];
     if (messageType == 'U' && data.Length == _updateMessageLength) { 
         float posX = System.BitConverter.ToSingle(data, 2);
         float posY = System.BitConverter.ToSingle(data, 6);
         float velX = System.BitConverter.ToSingle(data, 10);
         float velY = System.BitConverter.ToSingle(data, 14);
         float rotZ = System.BitConverter.ToSingle(data, 18);
         Debug.Log ("Player " + senderId + " is at (" + posX + ", " + posY + ") traveling (" + velX + ", " + velY + ") rotation " + rotZ);
         // We'd better tell our GameController about this.
         if (updateListener != null) {
             updateListener.UpdateReceived(senderId, posX, posY, velX, velY, rotZ);
         }
     }
 }

}

Thank you. :)

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

Answer by LuigiDUDE · Aug 03, 2017 at 12:49 PM

A little late, but if you are still stuck:

You are just missing the OnParticipantLeft function. Add this since you're using the RealTimeMultiplayerListener interface. Copy-paste this next function between OnLeftRoom() and OnPeersConnected(string[] participantsIds)

 public void OnParticipantLeft(Participant participant)
 {
     _instance.OnParticipantLeft(participant);
 }
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

91 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

Related Questions

Script to face the direction of the mouse only on the LocalPlayer? 1 Answer

Multiplayer Camera Problem! Help me plase 3 Answers

Build errors when using Photon 2 ,Build errors after using Photon 0 Answers

Animator().Play is not accepting variable 1 Answer

Failed to Re-Package Resources- Unity to Android 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