I'm running into a bit of an issue with a new project using TNet 3. Here's my code, and I'll explain what I'm trying to do ..
using UnityEngine;
using System.Collections;
using TNet;
public class TNetInGameManager : TNBehaviour {
public static TNetInGameManager Instance;
int masterIndex = 0;
void Start()
{
Instance = this;
}
public void AskForIndex()
{
Debug.Log("Asking for index from host : " + TNManager.GetHost(TNManager.lastChannelID).id);
Debug.Log("My Player ID: " + TNManager.playerID);
tno.Send("AskForPlayerIndex", TNManager.GetHost(TNManager.lastChannelID).id, TNManager.playerID);
// This causes even weirder behaviour.
//tno.Send("AskForPlayerIndex", Target.Host, TNManager.playerID);
}
[RFC]
void AskForPlayerIndex(int id)
{
Debug.Log("My Player ID: " + TNManager.playerID);
Debug.Log("Received index request from client " + id);
tno.Send("SendPlayerIndex", id, masterIndex);
masterIndex++;
}
[RFC]
void SendPlayerIndex(int ind)
{
Debug.Log("Received Index from Master!");
GameManager.instance.i = ind;
}
}
So when a client enters the channel, the player needs a 'slot' for the game (from 0 to 3). So when I join the channel, I call AskForIndex. This then should then send a simple request to the host of the channel to the method "AskForPlayerIndex". From there the host should then send a simple integer back to the requesting client via "SendPlayerIndex".
So it should send a request from Client -> Host -> Client. But what's actually happening is Client -> Client -> Client.
My Debug line logs out the correct Host ID ( TNManager.GetHost(TNManager.lastChannelID).id ), but for whatever reason on line 20, it's sending it to the local player instead. Any thoughts?
EDIT : Ugh time for me to take a break. Turns out all my weird TNet issues were being caused by an outdated dedicated TNet server. As soon as I used the TNServer.exe file in the TNet package, everything works as intended.