当前位置:网站首页>[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 .
边栏推荐
- MySQL practice: 4 Operation of data
- Using transformers of hugging face to realize text classification
- Learning signal integrity from scratch (SIPI) -- 3 challenges faced by Si and Si based design methods
- Mapping '/var/mobile/Library/Caches/com.apple.keyboards/images/tmp.gcyBAl37' failed: 'Invalid argume
- The best time to buy and sell stocks to get the maximum return
- opencv学习笔记三
- Go language shallow copy and deep copy
- MySQL query time period
- Discrete device ~ diode triode
- 2020-10-29
猜你喜欢

Embedded Software Engineer (6-15k) written examination interview experience sharing (fresh graduates)

Transformers loading Roberta to implement sequence annotation task

Cause analysis of serial communication overshoot and method of termination

Text to SQL model ----irnet

STM32 project design: an e-reader making tutorial based on stm32f4

Design of reverse five times voltage amplifier circuit

Necessary protection ring for weak current detection

2020-10-29

MySQL insert Chinese error

Go language shallow copy and deep copy
随机推荐
STM32 encountered problems using encoder module (library function version)
(3) Dynamic digital tube
Deploy wiki system Wiki in kubesphere JS and enable Chinese full-text retrieval
Can the encrypted JS code and variable name be cracked and restored?
Crawler case 1: JS reversely obtains HD Wallpapers of minimalist Wallpapers
Delete dictionary from list
教你几招:30句哄女孩的“霸道”温馨话,不看后悔!
loading view时,后面所有东西屏蔽
Relationship extraction --tplinker
STM32 project design: an e-reader making tutorial based on stm32f4
Embedded Software Engineer (6-15k) written examination interview experience sharing (fresh graduates)
MySQL query time period
MySQL insert Chinese error
Transformers loading Roberta to implement sequence annotation task
Realizing sequence annotation with transformers
(1) Turn on the LED
Relevant knowledge of DRF
1. error using XPath to locate tag
Necessary protection ring for weak current detection
STM32 porting mpu6050/9250 DMP official library (motion_driver_6.12) modifying and porting DMP simple tutorial