UI Buttons event triggers in multiplayer.

Hi all,

Having a bit of issue,
I can’t get onClick() public functions to send instructions to the server from a client.
It works fine when i’m acquiring inputs from the GetKeyDown function, but I just cant get it to work in a UI, server/client environment.

Help would be appreciated.

Below is my code.

using UnityEngine;
using System.Collections;
using UnityEngine.Networking;


public class RPCscript : NetworkBehaviour {


public Material mat;

    void Start ()
    {
    mat.color = Color.white;
    if(isServer)
        GetComponent<RPCscript>().enabled = false;
    if(isClient)
        GetComponent<RPCscript>().enabled = true;
   
    }

    void Update ()
    {
        if(Input.GetKeyDown (KeyCode.Q))
            {
            CmdBlackColor(Color.black);
            CmdHello ();
            }
       
        if(Input.GetKeyDown (KeyCode.E))
            CmdRedColor(Color.red);
    }
   
    [Command]
    public void CmdBlackColor(Color color)
    {
        mat.color = color;   
    }
   
    [Command]
    public void CmdHello()
    {
    Debug.Log ("Button Pressed!");
    }
   
    [Command]
    public void CmdRedColor(Color color)
    {
        mat.color = color;
    }
}

Apologies for not uploading the code the correct way.
Hope it is clear now.

I have solved the issue,

By nesting the CMD functions withing another public function.

That way when a click on the UI button is detected. unity will run the public function first and then it will run the CMD function resting within the public function.

Peace.