Question by
Working_Robot · May 25, 2016 at 09:41 PM ·
c#networkingserverclientcommand
Unet: [Command] not running
I have this code:
using UnityEngine;
using UnityEngine.Networking;
using System.Collections;
public class ChatPlayer : NetworkBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown (KeyCode.Q))
CmdHello ();
}
[Command]
void CmdHello(){
print ("Hello!");
}
}
This script is in a player spawn prefab, and as you can see, if you press q, the client sends a command to print hello in its console. When I do press q, the server, nor client gets a message saying "Hello!".
Comment
Answer by Working_Robot · May 25, 2016 at 09:59 PM
I had an inactive GameObject which was a copy of the prefab. I put my script there, instead of the actual prefab. :(