Search code examples
c#unity-game-enginewebsocketaugmented-reality

Downloading websocket in unity


i fin that i should download ths package (websocketdsharp) but when i did the outpout was the same.

when i tried to compile this c# script in unity

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using WebSocketSharp;
using TMPro;
public class Temperature : MonoBehaviour
{
 [SerializeField]
 private TextMeshPro textMesh = null;
 WebSocket ws;
 string messageWs;
 private void Start()
 {
 ws = new WebSocket("ws://192.168.1.8:1880/ws/Temperature");
 ws.Connect();
 }
 void Update()
 {
 ws.OnMessage += (sender, e) => messageWs = e.Data;
 if (textMesh == null)
 {
 textMesh = GetComponent<TextMeshPro>();
 }
 if (textMesh != null)
 {
 textMesh.text = $"Temperetaure : " + messageWs ;
 }
 }
}

the outpout was like this: Assets\Script\Temperature.cs(10,2): error CS0246: The type or namespace name 'WebSocket' could not be found (are you missing a using directive or an assembly reference?)


Solution

  • In "Assets/Script" directory, is there any assembly definition file(.asmdef)? If there it is, you should make it refer the WebSocketSharp package's asmdef, or remove the asmdef file in your Script folder.