- Home /
PhotonNetwork.IsClient, how to set tags for players?
Hello, I want to be able to use NavMesh&NavMesh agent in my multiplayer game. My plan is this: when you click one your minions and after that click on the other player's mininon i want it to set its target so i can move towards eachother and make them fight. I thought that I could do this by using tags on the player objects but when I try the code below It changes all the tags to Player2 which is obivious when you read the script but I can not figure it out how make this work just like I want. Or anyone has better way to do what I talked about? Thanks
players = GameObject.FindGameObjectsWithTag("Player");
if (PhotonNetwork.IsMasterClient == true)
{
foreach (GameObject playertemp in players)
{
playertemp.transform.gameObject.tag = "Player1";
}
}
else if (PhotonNetwork.IsMasterClient == false)
{
foreach (GameObject playertemp in players)
{
player.transform.gameObject.tag = "Player2";
}
}
Answer by Captain_Pineapple · Dec 17, 2019 at 12:13 PM
i do not think that you currently proposed approach will get you anywhere. especially since it limits you to having exactly 2 players in a room. also i am not sure if you undestood the concept of "IsMasterClient". It will be true at the one client which is the master client and your code would thus just tag all players as "Player1" in this gameinstance.
There are multiple way to distiguish different players from each other. In general it all boils down to the following: All PhotonViews have a "owner" which contain all information like nickname and so on. Access this data and choose a fiiting bit of information to distiguish the players.
then instead of tags use layers if you want to have a system like that. this way you can have e.g. 3 layers like "myUnits", "teamUnits" and "enemyUnits" and choose fitting actions accordingly. if you must have tags then i'd suggest to also tag them on a more general base like: tag is "myUnit" if photonView.isMine == true
Your answer
Follow this Question
Related Questions
Pacman ghost behaviour 0 Answers
How to queue NavMeshAgents on entering a tile in Unity (based on path distance to tile)? 0 Answers
How to prevent NavMeshAgents from colliding when warped to same position? 0 Answers
Navmeshagent stops with destination set 1 Answer
How to get a velocity unit vector from a NavMeshAgent? 1 Answer