// Use this for initialization private void Start() { GameObject lobbyCanvasObj = MainCanvasManager.Instance.LobbyCanvas.gameObject; LobbyCanvas lobbyCanvas = lobbyCanvasObj.GetComponent <LobbyCanvas>(); Button button = GetComponent <Button>(); if (lobbyCanvasObj == null) { return; } button.onClick.AddListener(() => lobbyCanvas.JoinRoomClick(RoomNameText.text)); }