void Start () {
Test = "Nothing yet happened";
NetworkServer.Listen(25000);
NetworkServer.RegisterHandler(888, ServerReceiveMessage);
}
private void ServerReceiveMessage(NetworkMessage message)
{
StringMessage msg = new StringMessage();
msg.value = message.ReadMessage<StringMessage>().value;
if (!String.IsNullOrEmpty(msg.value))
{
Test = "Message received";
string[] deltas = msg.value.Split('|');
Horizontal = Convert.ToSingle(deltas[0]);
Vertical = Convert.ToSingle(deltas[1]);
TestScript.MoveForward(Vertical);
TestScript.RotateAroundY(Horizontal);
}
else
{
Test = "Nothing received";
}
}
private void Connect()
{
client.Connect(IPAddress, 25000);
}
void Start () {
client = new NetworkClient();
Connect();
}
void Update () {
#if UNITY_ANDROID
MobileTouches = Input.touches;
if (MobileTouches.Length > 0)
{
for (int i = 0; i < MobileTouches.Length; i++)
{
if (MobileTouches[i].phase == TouchPhase.Moved)
{
Horizontal = MobileTouches[i].deltaPosition.x;
Vertical = MobileTouches[i].deltaPosition.y;
}else if(MobileTouches[i].phase == TouchPhase.Stationary)
{
Connect();
}
}
}
#elif UNITY_EDITOR
Horizontal = Input.GetAxis("Horizontal");
Vertical = Input.GetAxis("Vertical");
#endif
thumb.Translate(Vector3.up * Vertical * Time.deltaTime);
thumb.Translate(Vector3.right * Horizontal * Time.deltaTime);
SendControllerInfo();
}
static public void SendControllerInfo()
{
if (client.isConnected)
{
StringMessage msg = new StringMessage();
msg.value = Horizontal + "|" + Vertical;
client.Send(888, msg);
}
}