OnGUI with TrueSync

Hi everyone!

How can i change different variables using OnGUI or maybe canvas + button or other way?

i'm trying standart code, but it changed only on owner client and => Checksum: NOK

void OnGUI()
{
if (GUI.Button(new Rect(10, 10, 50, 50), "Click2"))
{
Xspeed1 += 2;
}

if (GUI.Button(new Rect(10, 70, 50, 30), "Click"))
{
Xspeed1 -= 2;
}
}


Same problem with canvas + button - it changed only on owner client

Thank you.

Best Answers

  • nuklius
    nuklius
    Accepted Answer
    done.
  • nuklius
    nuklius
    edited April 2017 Accepted Answer
    @feathers
    ButtonEvents - add on a button

    public void ButtonEvents(string EVENT)
    {
    switch (EVENT)
    {
    case "SpeedPlus":
    speedplus = true;
    break;
    }
    }


    public override void OnSyncedInput()
    {
    if (speedplus == true)
    {
    TrueSyncInput.SetByte(INPUT_KEY_SPEEDUP, 1);
    speedplus = false;
    }
    else
    TrueSyncInput.SetByte(INPUT_KEY_SPEEDUP, 0);
    }

    public override void OnSyncedUpdate()
    {

    if (TrueSyncInput.GetByte(INPUT_KEY_SPEEDUP) > 0)
    {
    Xspeed1 = Xspeed1 + 2;
    }
    .........................
    }

Answers

  • nuklius
    nuklius
    Accepted Answer
    done.
  • @nuklius could you please post the solution you came up with?
  • nuklius
    nuklius
    edited April 2017 Accepted Answer
    @feathers
    ButtonEvents - add on a button

    public void ButtonEvents(string EVENT)
    {
    switch (EVENT)
    {
    case "SpeedPlus":
    speedplus = true;
    break;
    }
    }


    public override void OnSyncedInput()
    {
    if (speedplus == true)
    {
    TrueSyncInput.SetByte(INPUT_KEY_SPEEDUP, 1);
    speedplus = false;
    }
    else
    TrueSyncInput.SetByte(INPUT_KEY_SPEEDUP, 0);
    }

    public override void OnSyncedUpdate()
    {

    if (TrueSyncInput.GetByte(INPUT_KEY_SPEEDUP) > 0)
    {
    Xspeed1 = Xspeed1 + 2;
    }
    .........................
    }