[英]How to send and get data in unet
I'm new to unity and unet.我是 unity 和 unet 的新手。 I'm trying to make a cricket game.
我正在尝试制作板球比赛。 I want to share a boolean variable between two clients.
我想在两个客户端之间共享一个布尔变量。
if(isBatting==null){
if (random.Next (0, 2) == 1) {
isBatting = true;
Instantiate(batsmanPrefab, batsmanPrefab.transform.position, batsmanPrefab.transform.rotation);
}else {
isBatting = false;
Instantiate(bowlerPrefab, bowlerPrefab.transform.position, bowlerPrefab.transform.rotation);
}
}else{
if(isBatting){
Instantiate(bowlerPrefab, bowlerPrefab.transform.position, bowlerPrefab.transform.rotation);
}else{
Instantiate(batsmanPrefab, batsmanPrefab.transform.position, batsmanPrefab.transform.rotation);
}
}
in the above code, when the first person joins the network, the code will randomly assign it to batting and bowling mode.在上面的代码中,当第一个人加入网络时,代码会随机将其分配到击球和保龄球模式。 Then when another joins, he will get the current state from that boolean and get its opposite mode.
然后当另一个加入时,他将从该布尔值中获取当前状态并获取其相反的模式。 But i am completely beginner in unity.
但我完全是统一的初学者。 So i have no idea, how to send and get data from the network server.
所以我不知道如何从网络服务器发送和获取数据。
need help...需要帮助...
One of the way, by using Command and RPC special methods.一种方法,通过使用 Command 和 RPC 特殊方法。
As you are newbie I will recommend you to learn UNET first.由于您是新手,我建议您先学习 UNET。 Here, are some useful links
这里有一些有用的链接
give sometime in learnig follow at least on tut and docs.在学习中花点时间至少关注 tut 和 docs。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.