UnityEngine.Networking.NetworkIdentity.AssignClientAuthority C# (CSharp) Method

AssignClientAuthority() public method

This assigns control of an object to a client via the client's NetworkConnection.

public AssignClientAuthority ( NetworkConnection conn ) : bool
conn NetworkConnection The connection of the client to assign authority to.
return bool
        public bool AssignClientAuthority(NetworkConnection conn)
        {
            if (!this.isServer)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("AssignClientAuthority can only be call on the server for spawned objects.");
                }
                return false;
            }
            if (!this.localPlayerAuthority)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("AssignClientAuthority can only be used for NetworkIdentity component with LocalPlayerAuthority set.");
                }
                return false;
            }
            if ((this.m_ClientAuthorityOwner != null) && (conn != this.m_ClientAuthorityOwner))
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("AssignClientAuthority for " + base.gameObject + " already has an owner. Use RemoveClientAuthority() first.");
                }
                return false;
            }
            if (conn == null)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("AssignClientAuthority for " + base.gameObject + " owner cannot be null. Use RemoveClientAuthority() instead.");
                }
                return false;
            }
            this.m_ClientAuthorityOwner = conn;
            this.m_ClientAuthorityOwner.AddOwnedObject(this);
            this.ForceAuthority(false);
            ClientAuthorityMessage msg = new ClientAuthorityMessage {
                netId = this.netId,
                authority = true
            };
            conn.Send(15, msg);
            if (clientAuthorityCallback != null)
            {
                clientAuthorityCallback(conn, this, true);
            }
            return true;
        }

Usage Example

Esempio n. 1
0
 void CmdChangeColor(GameObject go, Color c)
 {
     objNetId = go.GetComponent<NetworkIdentity>();
     objNetId.AssignClientAuthority(connectionToClient);
     RpcUpdateTower(go, c);
     objNetId.RemoveClientAuthority(connectionToClient);
 }