button listener problem

Options

Hello, I have a 1st script:

GameObject.Find("ScreenCanvas/butPas").GetComponent<Button>().onClick.RemoveAllListeners();  GameObject.Find("ScreenCanvas/butPas").GetComponent<Button>().onClick.AddListener(() => {           turnEnd.turnEndS.pl2atk = !turnEnd.turnEndS.pl2atk;       });

So I change bool pl2atk in 2nd script which synchronizing this value with Master using stream: stream.SendNext(pl2atk); e.t.c.

And it works well until I switch off this 1st script - then pl2atk turns to default "false". There was no such error before networking implementation. It even worked well without RemoveAllListeners(). What could it be?

Best Answer

  • Tobias
    Tobias admin
    Answer ✓
    Options

    We can not help here. This is too involved with the components of your project.

    Clean up the code, try to come up with a repro and if this is still a question about networking, ask again.

Answers

  • Tobias
    Tobias admin
    Answer ✓
    Options

    We can not help here. This is too involved with the components of your project.

    Clean up the code, try to come up with a repro and if this is still a question about networking, ask again.

  • Miha4406
    Miha4406
    edited September 2021
    Options

    Ok, Host creates GameLogic (IsMine: true(Master)) with bool pl2atk; and Client player creates GameLogic (IsMine: false(Master)) with bool pl2atk.

    When Client player presses the button, bool pl2atk in his GameLogic changes, but it's not changes in Host's GameLogic despite it's streamed. Why could it be?

    --------------------------

    Oh, ok there shouldn't be two of them in hierarchy, isn't it? My bad.