Author Topic: How to use GameServer.onPlayerConnect  (Read 485 times)

Doomlazy

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 1
  • Posts: 28
    • View Profile
How to use GameServer.onPlayerConnect
« on: January 19, 2018, 12:00:52 PM »
How do you use GameServer.onPlayerConnect ?

For example to print("player connected"); when a play connects to the game server.

devomage

  • Sr. Member
  • ****
  • Thank You
  • -Given: 7
  • -Receive: 67
  • Posts: 250
    • View Profile
Re: How to use GameServer.onPlayerConnect
« Reply #1 on: January 19, 2018, 07:26:20 PM »
this is covered in the tutorials...

http://www.tasharen.com/forum/index.php?topic=13953.0

  1. private void OnEnable()
  2. {
  3.         TNet.TNManager.onConnect += OnConnect;
  4. }
  5.  
  6. private void OnDisable()
  7. {
  8.         TNet.TNManager.onConnect -= OnConnect;
  9. }
  10.  
  11. private void OnConnect(bool success, string message)
  12. {
  13.         if (success)
  14.         {
  15.                 Debug.Log("player connected");
  16.         }
  17. }
  18.  

devomage

  • Sr. Member
  • ****
  • Thank You
  • -Given: 7
  • -Receive: 67
  • Posts: 250
    • View Profile
Re: How to use GameServer.onPlayerConnect
« Reply #2 on: January 19, 2018, 07:33:26 PM »
the above is for a client.  if you indeed want to add code to TNGameServer.cs

-- inside Start() and Stop() add your listeners:

  1. //start
  2. onPlayerConnect += MyMethod_OnPlayerConnect;
  3.  
  4. //stop
  5. onPlayerConnect -= MyMethod_OnPlayerConnect;
  6.