MultiConnectMultiConnectDocs Website home
MultiConnectSDK › Export to .NET

8. Load a prefab

Use the file's name without .mcprefab. Do this inside your room, or after the server has started.

Script 8.1: Loading Arena.mcprefab

#if UNITY_5_3_OR_NEWER
using UnityEngine;
#else
using MultiConnect.MultiConnectEngine;
using MultiConnect.Shared;
#endif

public class ArenaLoader
{
    public void Load()
    {
        // Loads MultiConnectPlugin/MultiConnectImports/Arena.mcprefab
        GameObject arena = GameObject.Instantiate("Arena");

        // Your script, with its exported field values (Script 3.1).
        var spawn = arena.GetComponentInChildren<SpawnPoint>();
        Console.WriteLine("Team " + spawn.team + " spawns at " + spawn.transform.position);

        // Field references are not exported, so connect objects here.
        GameObject door = arena.GetChild(0);
        Console.WriteLine("First child is " + door.name);
    }
}