-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUnityCsharpCode
84 lines (73 loc) · 1.89 KB
/
UnityCsharpCode
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using UnityEngine;
using System.Collections;
using System;
public class NewBehaviourScript : MonoBehaviour
{
public Material aaa;
public Material bbb;
public int result;
//public MovieTexture movie;
public int out_reply;
//把图片换成视频就能播放了
void Start()
{
//MovieTexture movie;
result = out_reply;
//result = UnityEngine.Random.Range(1, 100);
}
IEnumerator echoStart()
{
WebSocket w = new WebSocket(new Uri("ws://192.168.102.29:9091"));
yield return StartCoroutine(w.Connect());
w.SendString("Hi there");
int i = 0;
while (true)
{
string reply = w.RecvString();
if (reply != null)
{
Debug.Log("Received: " + reply);
out_reply = Convert.ToInt32(reply);
Debug.Log("Out_Received: " + out_reply);
w.SendString("Hi there" + i++);
}
if (w.error != null)
{
Debug.LogError("Error: " + w.error);
break;
}
yield return 0;
}
w.Close();
}
void Update()
{
//result = Random.Range (1, 100);
MovieTexture movie;
//result = out_reply;
if (result < 50)
{
if (aaa.mainTexture as MovieTexture)
{
movie = (MovieTexture)aaa.mainTexture;
movie.Play();
}
}
else
{
//movie.Stop();
}
if (result > 50)
{
if (bbb.mainTexture as MovieTexture)
{
movie = (MovieTexture)bbb.mainTexture;
movie.Play();
}
}
else
{
// movie.Stop();
}
}
}