Help!My commands seem lost!

Hey,I'm new to PUN and I just write a very simple example using command.

But I find it must be something wrong.

My example's code like this:


public override void SimulateController()
{
base.SimulateController();
if (Input.GetKeyDown(KeyCode.J))
{
IPlayerInputKeyDownInput input = PlayerInputKeyDown.Create();
input.keyType = 1;
entity.QueueInput(input);
}
}

public override void ExecuteCommand(Command command, bool resetState)
{
if (entity.isOwner)
{
Debug.Log("Excute Command " + command);
}
}

I only use BoltNetwork.Instantiate to create the entity in server and mark every other client is the controller.

when I run the scene locally(The server and the client are all in my computer),

I press key J in client , if I see the log in the server side ,it means that the server receive the command ,right?

But when I press J in client,it seems there are 90% probability to lose the command.It only print 1/10 logs in server side.

Best Answer

  • awang
    awang
    Answer ✓
    Finally soved the problem.

    I should not use Input.GetKeyDown(KeyCode.J) in SimulateController.It should be in Update.

Answers

  • awang
    awang
    Answer ✓
    Finally soved the problem.

    I should not use Input.GetKeyDown(KeyCode.J) in SimulateController.It should be in Update.