![alt text][1]I am trying to build a websocket and try to play the animation using the server.
Ref:-**https://www.youtube.com/watch?v=13HnJPstnDM**
My unity code :---
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using WebSocketSharp;
public class webSoct : MonoBehaviour
{
WebSocket ws;
//Using Animator
private Animator anim;
//Using Animation
//private Animation anim;
bool isALL_anim = false;
private void Start()
{
//For Animator
anim = GetComponent();
//For Animation
//anim = gameObject.GetComponent();
ws = new WebSocket("ws://localhost:8080");
//For remote server
//wss = new WebSocket("wss://...");
ws.Connect();
ws.OnMessage += (sender, e) =>
{
Debug.Log("Message Received from " + ((WebSocket)sender).Url + ", Data : " + e.Data);
//Not working when i'm receive data from the user
Debug.Log(isALL_anim);
anim.SetBool("ALL_animation", isALL_anim);
//Debug.Log(isALL_anim);
};
}
//private void Update is not working
void Update()
{
isALL_anim = true;
if (ws == null)
{
//anim.SetBool("ALL_animation", isALL_anim);
return;
//anim.Play("F_allanimation");
}
//Using space bar
//if (Input.GetKey(KeyCode.Space))
//{
// Debug.Log("Souradeep Ash");
// isALL_anim = Input.GetKey(KeyCode.Space);
// //Checking animation working or not
// Debug.Log("isALL_anim");
// anim.SetBool("ALL_animation", isALL_anim);
// wss.Send("Hello");
//}
//Not working with if-else
//if (Input.GetKey(KeyCode.Space))
//{
// anim.SetBool("ALL_animation", isALL_anim);
//}
//Trying Something New
//ws.OnMessage += (sender, e) =>
//{
// //ws.Send("NO");
// //Debug.Log(isALL_anim);
// //anim.SetBool("ALL_animation", isALL_anim);
// if (e.Data == "anim")
// {
// //Debug.Log(isALL_anim);
// //ws.Send("HI");
// anim.SetBool("ALL_animation", isALL_anim);
// }
//};
//Working for this one but only when i'm pressing Space button
//isALL_anim = Input.GetKey(KeyCode.Space);
//Debug.Log(isALL_anim);
//anim.SetBool("ALL_animation", isALL_anim);
}
}
please check and guide me how can i will make it run
Ref for the project:--- "https://www.youtube.com/watch?v=13HnJPstnDM"
if any one help with this or give any other solution
**How can i will controll the animation using a web API (Realtime)**
[1]: /storage/temp/199549-unityquestions.png
↧