- Home /
Using AssignClientAuthority
Now I an testing on easy online project, inwhich cube player bumps to a sphere then the player gets authority on the shere. But, I am struggling a problem. I can set authority to sphere, however never becomes "isLocal". Player Objects have "GamePlayer" tag, The sphere has "GameObj" tag.
void Update () {
if (isLocalPlayer)
{
Debug.Log("yes");
this.gameObject.transform.Rotate(new Vector3(0, 0, 30));
}
}
private void OnCollisionEnter(Collision collision)
{
if(isServer && collision.gameObject.CompareTag("GamePlayer"))
{
NetworkIdentity player = collision.gameObject.GetComponent<NetworkIdentity>();
NetworkIdentity self = this.gameObject.GetComponent<NetworkIdentity>();
collision.gameObject.GetComponent<PlayerMove>().CmdSetAuth(netId, player);
}
}
This code is attached to the sphere.
[Command]
public void CmdSetAuth(NetworkInstanceId objectId, NetworkIdentity player)
{
var iObject = NetworkServer.FindLocalObject(objectId);
var networkIdentity = iObject.GetComponent<NetworkIdentity>();
var otherOwner = networkIdentity.clientAuthorityOwner;
if (otherOwner == player.clientAuthorityOwner)
{
Debug.Log("Same");
return;
}
else
{
if (otherOwner != null)
{
networkIdentity.RemoveClientAuthority(otherOwner);
}
networkIdentity.AssignClientAuthority(player.connectionToClient);
}
}
This code is set to player object.
It seems assignment is successfully done. However "yes" never appears on Log. Only a little help will helpful for me. Thank you in advance.
Your answer
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
Why can't the client move a networked object ? 1 Answer
Making own server instead of using unity matchmaking and relay servers? 1 Answer
[Multiplayer] Lobby/Staging/Matchmaking flow: Quickstart using NetworkLobbyManager? 2 Answers
Can I use the Unity networking HLAPI without paying for the Unity Multiplayer service? 0 Answers