Hi!
I’m working on a multiplayer videogame and one of my scripts pseudo-code looks like:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class DoStuff : NetworkBehaviour
{
// Update is called once per frame
void Update()
{
//Only usable on client-side
if (!isServer) {
return;
}
else {
if (Input.GetMouseButtonDown(0))
{
StartCoroutine(CmdCoroutine());
}
}
}
//Called on client-side but executed on Server to inform all the clients
[Command]
IEnumerator CmdCoroutine()
{
while (condition)
{
//doStuff
yield return new WaitForSeconds(0);
}
}
}
As you can see, I want that when client click his mouse start a coroutine on the server using the “[Command]” syntax, so other clients can saw the “stuff” the client has done.
My problem is that unity debug says
“Command Function cannot be a coroutine”
Then my question is:
How can I skip this kind of behaviour?
I really need to do my stuff on a coroutine started by client, and the things he made, have to be seen by the rest.
Thanks for your time and point of view!