#im having an "issue" with my code for a button

19 messages · Page 1 of 1 (latest)

ancient solstice
#

if ur familiar with Netcode in the inspector there are these 3 buttons

#

"Start Server"
"Start Host"
"Start Client"

#

i only want to use the Start Host and Start Client of the thing

#

and as u can see in my game i have 2 buttons too

#

one for the host and one for the client

#

basically what its supposed to do is if i click the Host Button it should do the same thing as the "start Host" in the inspector

#

which is easy cause i am using the singleton thing

#
using UnityEngine;
using UnityEngine.UI;
using Unity.Netcode;

public class NetworkManagerUI : MonoBehaviour
{
    [SerializeField] private Button HostButton;
    [SerializeField] private Button ConnectButton;

    private void OnAwake()
    {
        HostButton.onClick.AddListener(() => {
            NetworkManager.Singleton.StartHost();
        });

        ConnectButton.onClick.AddListener(() => {
            NetworkManager.Singleton.StartClient();
        });
    }

}

#

this is what the code looks like

#

now its simple but the issue is its not working

#

the way i know its the buttons that are the issue and not the Netcode Manager itself its cause if i press the "Start Host" button thru the console it does what it should do

#

and after checking the Host button in my game does nothing if i click it

#

i did exactly the same thing as the tutorial same code too but why am i have this issue?

#

now usually i would just ignore it and keep working but the issue is i cant test out the "multiplayer" in my game as i only have 1 client, the way i do this and prob everyone else, is i build a copy of the game and use that as the client and the game in the editor is the host, but i cant use the buttons therefor i cant debug or work

ancient solstice
#

code from tutorial

#

my code

topaz sluice
#

your code says "OnAwake" while the tutorial one is just "Awake"

ancient solstice
#

omg

#

my brain must be build like an expired chicken nugget