Why is my isLocalPlayer not working ?
Hello,
I'm trying to do a multiplayer game with unity using NetworkBehaviour in VR. To do so, I want to make sure the teleportation is only available to the player who triggers it. For the player who start the game with the server (host), everything is perfect. He can only teleport himself. Except that the client that connects to the host can teleport anyone, which I would want to avoid. Here is my code from the file "Player.cs" :
public GameObject Teleportation;
private void Start()
{
if (isServer)
{
Debug.Log("I am the server");
RpcAllowTeleportation();
}
else
{
Debug.Log("I am the client");
CmdAllowTeleportations();
}
}
[Command]
public void CmdAllowTeleportations()
{
Debug.Log("C'est passé par la fonction CmdAllowTeleportation (client)");
if (!hasAuthority) { Teleportation.GetComponent<Teleport>().enabled = false; Debug.Log("cmd (client) : it hasn't the authority"); }
else { Debug.Log("cmd (client) : It has the authority"); }
}
[ClientRpc]
void RpcAllowTeleportation()
{
Debug.Log("It passed through the function RpcAllowTeleportation (serveur)");
if (!isLocalPlayer) { Teleportation.GetComponent<Teleport>().enabled = false; Debug.Log("rpc (serveur) : it hasn't the authority"); }
else { Debug.Log("rpc (serveur) : It has the authority"); }
}
and here is my object :
Could you help me please ? I really don't know what to do ...
I forgot to mention it : this is a prefab I instantiate somwhere else and I specify which Teleporting object this with a grab and drop in unity
Your answer
Follow this Question
Related Questions
Trying to teleport my character to mouse position (2d with perspective view) 0 Answers
How do i make my 2d character teleport?,How do i create a Teleport movment for a 2d character? 0 Answers
I want that a speciefied player to control a car, not all players (Network). How can I do this? 2 Answers
multi player game but the players does'nt see each other 0 Answers
Syncing Gameobject variables 0 Answers