Unity SDK

v1.0.0

Integrate Game On Dude! into your Unity project with our official SDK.

Installation

Unity Package Manager (Recommended)

Install via Git URL in Unity Package Manager

  1. 1Open Unity and go to Window → Package Manager
  2. 2Click the + button and select "Add package from git URL"
  3. 3Enter: https://github.com/gameon-guy/unity-sdk.git
  4. 4Click Add and wait for installation

Manual Installation

Download and import the Unity package

  1. 1Download the latest .unitypackage from GitHub Releases
  2. 2In Unity, go to Assets → Import Package → Custom Package
  3. 3Select the downloaded file and import all assets

Requirements

  • Unity 2021.3 LTS or newer
  • .NET Standard 2.1 or .NET 4.x
  • WebSocket support (included in Unity)
  • Newtonsoft.Json (included with SDK)

Components

GameOnNetworkManager

Core component for managing server connections and rooms.

Properties

serverUrl(string)WebSocket server URL
autoConnect(bool)Connect on Start()
reconnectAttempts(int)Max reconnection attempts

Events

OnConnectedFired when connected to server
OnDisconnectedFired when disconnected
OnRoomJoinedFired when joined a room
OnRoomLeftFired when left a room
OnErrorFired on connection errors

Example

using GameOn.Multiplayer;
using UnityEngine;

public class GameManager : MonoBehaviour
{
    [SerializeField] private GameOnNetworkManager networkManager;

    async void Start()
    {
        networkManager.OnConnected += () => Debug.Log("Connected!");
        networkManager.OnRoomJoined += OnRoomJoined;

        await networkManager.Connect();
    }

    async void JoinGame()
    {
        await networkManager.JoinOrCreate("trivia", new {
            username = "Player1",
            team = "blue"
        });
    }

    void OnRoomJoined(Room room)
    {
        Debug.Log($"Joined room: {room.Id}");

        room.OnStateChange += (state) => {
            // Update game UI based on state
            UpdateUI(state);
        };

        room.OnMessage<ChatMessage>("chat", (msg) => {
            chatUI.AddMessage(msg.from, msg.text);
        });
    }
}

GameOnTriviaManager

Specialized component for trivia game functionality.

Properties

networkManager(GameOnNetworkManager)Reference to network manager
questionTimeLimit(float)Seconds per question

Events

OnQuestionReceivedNew question from server
OnAnswerResultResult of submitted answer
OnScoresUpdatedScores changed
OnGameEndedGame finished

Example

using GameOn.Multiplayer;
using UnityEngine;
using UnityEngine.UI;

public class TriviaGameUI : MonoBehaviour
{
    [SerializeField] private GameOnTriviaManager triviaManager;
    [SerializeField] private Text questionText;
    [SerializeField] private Button[] answerButtons;

    void OnEnable()
    {
        triviaManager.OnQuestionReceived += DisplayQuestion;
        triviaManager.OnAnswerResult += ShowResult;
        triviaManager.OnScoresUpdated += UpdateScoreboard;
    }

    void DisplayQuestion(TriviaQuestion question)
    {
        questionText.text = question.text;

        for (int i = 0; i < answerButtons.Length; i++)
        {
            int index = i;
            answerButtons[i].GetComponentInChildren<Text>().text =
                question.answers[i];
            answerButtons[i].onClick.AddListener(() =>
                triviaManager.SubmitAnswer(index));
        }
    }

    void ShowResult(AnswerResult result)
    {
        if (result.correct)
            Debug.Log($"Correct! +{result.points} points");
        else
            Debug.Log($"Wrong! Correct answer: {result.correctAnswer}");
    }
}

NetworkTransform

Automatically sync transform between clients with interpolation.

Properties

syncPosition(bool)Sync position
syncRotation(bool)Sync rotation
syncScale(bool)Sync scale
interpolationSpeed(float)Smoothing factor
sendRate(float)Updates per second

Example

// Simply add NetworkTransform component to your GameObject
// Configure in Inspector or via code:

using GameOn.Multiplayer;
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    private NetworkTransform netTransform;

    void Awake()
    {
        netTransform = GetComponent<NetworkTransform>();
        netTransform.syncPosition = true;
        netTransform.syncRotation = true;
        netTransform.interpolationSpeed = 10f;
        netTransform.sendRate = 20f; // 20 updates/sec
    }

    void Update()
    {
        if (netTransform.IsOwner)
        {
            // Only owner can move
            float h = Input.GetAxis("Horizontal");
            float v = Input.GetAxis("Vertical");
            transform.Translate(new Vector3(h, 0, v) * Time.deltaTime * 5f);
        }
        // Other clients automatically receive interpolated updates
    }
}

Migration from Photon

Switching from Photon? Here's a quick reference for equivalent APIs.

PhotonGameOnNotes
PhotonNetwork.ConnectUsingSettings()await networkManager.Connect()GameOn uses async/await for all network operations
PhotonNetwork.JoinOrCreateRoom("room", options, lobby)await networkManager.JoinOrCreate("room", options)Simplified API without lobby system
[PunRPC] void MyRPC()room.OnMessage<T>("type", handler)Message-based instead of RPC attributes
PhotonView.IsMinenetworkTransform.IsOwnerOwnership works similarly
PhotonNetwork.CurrentRoom.PlayerCountroom.State.players.CountAccess through synchronized state

Note: While GameOn provides similar functionality to Photon, the APIs are designed differently. We recommend reviewing the full documentation rather than doing a 1:1 port.

Ready to Build?

Check out our tutorials for building complete multiplayer games with Unity.