Hi,
A couple of days ago I jumped to a unity network project without previous knowledge of unity and not a great knowledge about multiplayer online networking.
I am working on an online team deatchmatch multiplayer, and the next class should allow each player to see the right information about the other players (the name and the team color).
using UnityEngine;
using System.Collections;
public class NetworkNameUpdate : MonoBehaviour
{
public TextMesh nameText;
public NetworkView networkView;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
//check if this is causing constant RPC calls
if (nameText networkView (NetworkManager.GetPlayer(networkView) != null))
{
nameText.text = NetworkManager.GetPlayer(networkView).name;
if (NetworkManager.GetPlayer(networkView).team==0)
{
nameText.renderer.material.color = Color.blue;
}
else
{
nameText.renderer.material.color = Color.red;
}
}
}
}
So if, for example I am player 1, this code is executed on the player 2 and player 3 instances that the server created.
As you can see, in the class there is a pointer to the network view that manages that instance. The problem is, all the network views of those instances in my client computer point to the server. So when I use the function NetworkManager.GetPlayer(networkView), it always returns the Player that is running on the server computer. Is there any chance to make the network views owners be the real players instead of the server?if not, how can I identify from that component who is the real player?
I want to highlight that I can access at anytime to a list of all the players, with their own ID, team color and name. Thanks in advance for the help!