当前位置:网站首页>[unity mirror] use of networkteam
[unity mirror] use of networkteam
2022-06-26 08:31:00 【_ YiFei】
【Unity Mirror】NetworkTeam Use
Function description
A recent demand is the invitation function of personal space : Everyone can enter their own space to dress up furniture, etc , At the same time, you can invite your friends to visit your own space , When invited, two people appear in the same space , You can see each other ; But when not invited , You can only enter your own space , And see no one else . So I thought of using NetworkTeam To complete .
NetworkTeam brief introduction
mirror Introduction to the official website :
Team management uses network team components on player objects and network objects that need to restrict their visibility to the team , Provides networking objects that are visible only to people on the same team . take Network Team Components are added to player prefabs and any other prefabs belonging to the team . At run time, players in the same team / Object's team ID Set to the same value .
Ideas
When everyone enters their own space , Set up your own TeamId For their own userid, So that everyone else can TeamId Different , He can only see himself but not others . When invited , To his own TeamId Change to the invitee's userid, So we can see each other .
Start making
The first two steps and Mirror The official ones are the same , Just look at the back .
- First of all, will Team Interest Management Component added to and Network Manager In the same object :

- Then add our players Network Team Components

- Code writing
It is worth noting that , The official website says that if we want two people to join the same Team Words , It only needs ** At run time, players in the same team / Object's team ID Set to the same value .**
When writing code, we may directly follow the following TeamId Revised :( For example OnStartLocalPlayer() This code is written in )
GetComponent<NetworkTeam>().teamId = userid;
But this is actually wrong , Because this only runs on the local client , The server doesn't know , That is to say, our code must be run on the server , Only in this way can the server modify this player's teamid, Here is the correct code :
[Command]
public void CmdChangeTeam(string teamid)
{
GetComponent<NetworkTeam>().teamId = teamid;
}
When it needs to be modified teamid when , Call this method , utilize Command, This method actually runs on the server instead of the local client , In this way, the server can know the player's Teamid Changed , It can also divide him into the same team , Let the players in the same team see each other , In this way, the invitation function can be easily implemented .
边栏推荐
- optee中的timer代码导读
- Undefined symbols for architecture i386 is related to third-party compiled static libraries
- xxl-job配置告警邮件通知
- nn. Modulelist and nn Sequential
- Opencv learning notes 3
- 2020-10-29
- 加密的JS代码,变量名能破解还原吗?
- How to Use Instruments in Xcode
- Deploy wiki system Wiki in kubesphere JS and enable Chinese full-text retrieval
- Transformers loading Roberta to implement sequence annotation task
猜你喜欢

opencv學習筆記三

Oracle 19C download installation steps

Use of jupyter notebook

利用无线技术实现分散传感器信号远程集中控制

(vs2019 MFC connects to MySQL) make a simple login interface (detailed)

2020-10-20

Reflection example of ads2020 simulation signal

Esp8266wifi module tutorial: punctual atom atk-esp8266 for network communication, single chip microcomputer and computer, single chip microcomputer and mobile phone to send data

Relation extraction model -- spit model

Relationship extraction --r-bert
随机推荐
golang json unsupported value: NaN 处理
Fabrication of modulation and demodulation circuit
The best time to buy and sell stocks to get the maximum return
loading view时,后面所有东西屏蔽
Undefined symbols for architecture i386 is related to third-party compiled static libraries
Vs2019-mfc setting edit control and static text font size
STM32 project design: temperature, humidity and air quality alarm, sharing source code and PCB
Deploy wiki system Wiki in kubesphere JS and enable Chinese full-text retrieval
Introduction of laser drive circuit
FFmpeg音视频播放器实现
2020-10-17
Recognize the interruption of 80s51
opencv學習筆記三
Leetcode22 summary of types of questions brushing in 2002 (XII) and collection search
加密的JS代码,变量名能破解还原吗?
MySQL practice: 1 Common database commands
Oracle database self study notes
opencv学习笔记二
STM32 project design: smart door lock PCB and source code based on stm32f1 (4 unlocking methods)
Recovering the system with Clonezilla USB disk