Search Unity

Resolved access unity transport via code

Discussion in 'Unity Transport' started by miccalisto, Apr 21, 2023.

  1. miccalisto

    miccalisto

    Joined:
    Feb 20, 2018
    Posts:
    40
    How do I access unity transport with code? I want to change the protocol from relay unity transport to unity transport depending on whether it's a singleplayer or multiplayer mode.
    How do I do that?
     
  2. simon-lemay-unity

    simon-lemay-unity

    Unity Technologies

    Joined:
    Jul 19, 2021
    Posts:
    441
    Just access the
    UnityTransport
    component on the game object where your
    NetworkManager
    is. Here's an example where this is done to configure the Relay parameters. To change the transport between using Relay and direct connections, simply configure it with the appropriate parameters. Calling
    SetRelayServerData
    will automatically change the protocol type to Relay, and calling
    SetConnectionData
    will automatically set it to use direct connections.
     
    FactotumDigital, CodeSmile and MMMIU like this.