Simple TCP/IP Unity Code

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
(New page: After you have the DLL in your plugins folder, create a c# script file and place this code in that file then attach it to either an empty game object or the main camera. <c> using UnityEng...)
 
Line 1: Line 1:
 +
*[[Simple TCP/IP Client - Server]] - Return to TCP/IP Client - Server Page
 +
 
After you have the DLL in your plugins folder, create a c# script file and place this code in that file then attach it to either an empty game object or the main camera.
 
After you have the DLL in your plugins folder, create a c# script file and place this code in that file then attach it to either an empty game object or the main camera.
 
<c>
 
<c>

Revision as of 14:45, 15 June 2007

After you have the DLL in your plugins folder, create a c# script file and place this code in that file then attach it to either an empty game object or the main camera. <c> using UnityEngine; using System.Collections; using System.Runtime.InteropServices; using SharpConnect; using System.Security.Permissions;

public class LinkSyncSCR : MonoBehaviour { public Connector test=new Connector(); string lastMessage; public Transform PlayerCoord;

void Start () { Debug.Log(test.fnConnectResult("Your server IP or URL without HTTP://",10000,System.Environment.MachineName)); if (test.res !="") { Debug.Log(test.res); }

} void Update () { if (Input.GetKeyDown ("space")) { Debug.Log ("space key was pressed"); test.fnPacketTest("space key was pressed"); }

if (Input.GetKeyDown ("escape")) { Debug.Log ("escape key was pressed"); test.fnPacketTest("escape key was pressed"); } if (test.strMessage !="JOIN") { if (test.res != lastMessage) { Debug.Log(test.res); lastMessage=test.res; } } test.fnPacketTest(PlayerCoord.position[0]+","+PlayerCoord.position[1]+","+PlayerCoord.position[2]); }

void OnApplicationQuit (){ try{test.fnDisconnect();} catch{} } } </c>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox