access unity transport via code

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?

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.

4 Likes