- Home /
Question by
behrangtaheri · Jan 26, 2018 at 07:54 PM ·
c#networkingnetworkcommandauthoritative
Trying to send command for object without authority. - change color of object from client
Hi I'm trying to change color of my object from client... if I change it from host I can see it on client also with errors but I can still show changes on client but vice versa nothing happen and this is important. just show this error Trying to send command for object without authority.
I attach below code to my sphere (I also click on update ) and then put my sphere in player prefab on the spawn info section of my networkmanager script.So my sphere spawn on my scene. this is my code ..what is wrong with it. I put a button on my canvas and Cmd command will be called when user click on that button.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class sendataagain : NetworkBehaviour {
// public GameObject myobj;
[SyncVar]
private Color objectColor;
[SyncVar]
private GameObject objectID;
[SyncVar]
//public GameObject myobj;
private NetworkIdentity objNetId;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public void justsendit()
{
CmdSendName( Color.white);
}
[Command]
void CmdSendName(Color name)
{
objNetId = GetComponent<NetworkIdentity>();
objNetId.AssignClientAuthority(connectionToClient);
RpcUpdateColor(name);
objNetId.RemoveClientAuthority(connectionToClient);
}
[ClientRpc]
void RpcUpdateColor( Color name)
{
// transform.name = name;
GetComponent<Renderer>().sharedMaterial.color = name;
}
}
Comment