タイトルが示すように、クライアントから送信されたコマンドがトリガーされないという問題があります。
私が機能させようとしている基本的な機能は、敵がプレイヤーの前にいてクリックすると、そのプレイヤーが一瞬気絶することです。私がホストの場合は問題なく動作し、両側が完全に登録されます。
クライアントとしてプレイしている場合、コマンドを「送信する必要がある」ところまで到達しますが、「非ローカル プレイヤーにコマンドを送信しようとしています」という警告が表示されることに気付きました。同様に、どちらの側でも何も起こりません。明らかに、私はクライアント側で何か間違ったことをしているに違いありませんが、これについて他にどのような方法があるのか わかりません。
「問題」コード。
if (Input.GetButtonDown("Fire1")) {
Ray ray = new Ray(transform.position, transform.forward);
RaycastHit hit = new RaycastHit();
Physics.Raycast(ray, out hit, 20f);
if (hit.transform != null) {
if (hit.rigidbody != null) {
PlayerController controller = hit.rigidbody.GetComponent<PlayerController>();
if (controller != null) {
if (!controller.stunned) {
// Send the stun command to the server
controller.CmdStun();
}
}
}
}
}
メソッド呼び出し
[Command]
public void CmdStun() {
// Report that the stun was sent
UnityEngine.Debug.Log("Stun Sent");
RpcStun();
}
[ClientRpc]
public void RpcStun() {
// Activate the stun timer.
stunTimer.Start();
// Track the players original color.
normalColor = manager.color;
// Make the players bot look like its shut down.
manager.InitiateColorChange(Color.black);
// Other code will check against this before trying to send another stun command.
stunned = true;
}
編集: リクエストに応じて、2 つのスクリプト全体をここに示します。
Unity でのプレーヤー構成:
https://gyazo.com/400c5b3a95c1a58f9b6e930b0c3c853b
https://gyazo.com/c17a7317767a00e2150ff34b03a03e8f
https://gyazo.com/322731aefbe69f9567d2b395523b8f2a
完全な警告メッセージ
ローカル以外のプレーヤーにコマンドを送信しようとしています。UnityEngine.Networking.NetworkBehaviour:SendCommandInternal(NetworkWriter, Int32, String) PlayerController:CallCmdStun() ObjectInteractor:Update() (Assets/Scripts/ObjectInteractor.cs:58)