MENU

Part IV : Send your position to Unity

In this part we will see how to retrieve the position in Unity and assign it to the main camera. We won’t go through the setup of Unity as you’ll find all the information you need online. You will have to install Websocket Sharp package (either the DLL or buy the Unity package for 15$ on the asset store). Here is the script you will have to use to connect to the Gateway¬†websocket, get your position and send it to the camera. You just to add it into your project and call it somewhere as a component. using UnityEngine; using System.Collections; using WebSocketSharp;   public class WebSocketCameras : MonoBehaviour {   private WebSocket ws; private bool detecting = false; private Vector3 position; private Vector3 position2; private string GatewayIP = "192.168.1.101"; // Set your gateway IP here private string WebsocketPort = "9014"; Camera mainCam;     void Start () {   // Retrieve the main camera mainCam = Camera.main;   // Create and Open the websocket ws = new WebSocket("ws://"+ GatewayIP + ":" + WebsocketPort); ws.OnOpen += OnOpenHandler; ws.OnMessage += OnMessageHandler; ws.OnClose += OnCloseHandler;   ws.ConnectAsync();   }   private void OnOpenHandler(object sender, System.EventArgs e) { Debug.Log("WebSocket connected!"); }   private […]
Read More ›
Skip to toolbar