Skip to content

Creating Custom Scripts

Nathan Gill edited this page Nov 23, 2020 · 3 revisions

Any DLL file placed inside your map folder will be loaded with your map, so to include custom scripts you will need to create a class library project.

Creating the project

In visual studio, create a new project. Search the templates for "Class Library", and select "Class Library (.NET Framework)".
Configure the project to your liking, but make sure to select the .NET Framework 3.5 as this is the latest version of the framework that the game's version of Unity supports.

Since this project was created by Visual Studio instead of Unity, it won't automatically have references to Unity's libraries, so we will add them manually. In the Solution Explorer window of Visual Studio, right click on your project and select Add > Reference, then in the dialogue, click Browse. You will have to add the following libraries;

Assembly Location Required?
Unity Engine *H3VR install folder*\h3vr_Data\Managed\UnityEngine.dll Yes
Unity Engine UI *H3VR install folder*\h3vr_Data\Managed\UnityEngine.UI.dll Yes
H3VR *H3VR install folder*\h3vr_Data\Managed\Assembly-CSharp.dll Technically no, but if you want to interface with any of the game's code then yes
WurstMod Any WurstMod.dll. (In your game's plugin folder or your Unity project's plugin folder) No, unless you are making your own mapping components
Unity Editor *Your Unity 5.6.3 install folder*\Editor\Data\Managed\UnityEditor.dll No, unless you are making your own Unity Editor tools

Creating your custom scripts

Once you have all the references added, you can now start coding. You can use all of the Unity libraries normally and you also have access to H3VR's code. We can test to make sure everything is setup properly by replacing the code in the auto-generated Class1 file with the following:

using UnityEngine;

public class Class1 : MonoBehaviour
{
    // Update is called every frame
    private void Update()
    {
        // Move this object forward by 10cm every second
        transform.Translate(transform.forward * 0.1f * Time.deltaTime);
    }
}

Normally in Unity when you edit a file it automatically compiles, but since we're not in Unity we'll have to do that ourselves. In Visual Studio, on the menu bar, select Build > Build Solution. This should only take a second or two and will create a DLL file that now contains this class we just made. It's located at *your project folder*\bin\debug\*your project name*.dll. Copy this file to the plugins folder in your Unity project.

Using your custom scripts

When Unity is finished importing, you will now be able to add the 'Class 1' component to any object in your map, so go ahead and add at least one object with the new script and when done, export your map as normal. Finally, to use your scripts in-game you can add your compiled DLL file to your level's Deli mod folder and add an entry in the mod manifest for it.

Clone this wiki locally